'How to install Perl DBD::Oracle with Oracle Instant Client on macOS Catalina
I'm running macOS Catalina 10.15.7 and I need to install Oracle Instant Client to run run a Perl script that connects to a DB.
1. Installing Oracle Instant Client
I downloaded the packages I needed:
- Basic Light Package (DMG)
- SDK Package (DMG)
- ODBC Package (DMG)
From Instant Client 19.8 and followed the installation instructions without any issues (just copying and pasting)
The files are extracted in
/Users/username/Downloads/instantclient_19_8
2. Setting ORACLE_HOME
Next, I did set ORACLE_HOME to /Users/username/Downloads/instantclient_19_8
export ORACLE_HOME=/Users/username/Downloads/instantclient_19_8
3. Installing DBD::Oracle
When I tried to install DBD::Oracle
I got the following error:
$ cpanm DBD::Oracle
--> Working on DBD::Oracle
Fetching http://www.cpan.org/authors/id/M/MJ/MJEVANS/DBD-Oracle-1.80.tar.gz ... OK
Configuring DBD-Oracle-1.80 ... N/A
! Configure failed for DBD-Oracle-1.80. See /Users/username/.cpanm/work/1608142485.48272/build.log for details.
The log file's content:
$ cat /Users/username/.cpanm/work/1608142485.48272/build.log
cpanm (App::cpanminus) 1.7044 on perl 5.032000 built for darwin-thread-multi-2level
Work directory is /Users/username/.cpanm/work/1608142485.48272
You have make /usr/bin/make
You have LWP 6.47
You have /usr/bin/tar: bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.6
You have /usr/bin/unzip
Searching DBD::Oracle () on cpanmetadb ...
--> Working on DBD::Oracle
Fetching http://www.cpan.org/authors/id/M/MJ/MJEVANS/DBD-Oracle-1.80.tar.gz
-> OK
Unpacking DBD-Oracle-1.80.tar.gz
Entering DBD-Oracle-1.80
Checking configure dependencies from META.json
Checking if you have Config 0 ... Yes (5.032000)
Checking if you have Encode 0 ... Yes (3.06)
Checking if you have Math::BigInt 0 ... Yes (1.999818)
Checking if you have Devel::Peek 0 ... Yes (1.28)
Checking if you have Test::More 0 ... Yes (1.302177)
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.44)
Checking if you have Data::Dumper 0 ... Yes (2.174)
Checking if you have DBI 1.623 ... Yes (1.643)
Checking if you have Test::NoWarnings 0 ... Yes (1.04)
Configuring DBD-Oracle-1.80
Running Makefile.PL
Using DBI 1.643 (for perl 5.032000 on darwin-thread-multi-2level) installed in /usr/local/Cellar/perl/5.32.0/lib/perl5/site_perl/5.32.0/darwin-thread-multi-2level/auto/DBI/
Configuring DBD::Oracle for perl 5.032000 on darwin (darwin-thread-multi-2level)
If you encounter any problem, a collection of troubleshooting
guides are available under lib/DBD/Oracle/Troubleshooting.
'DBD::Oracle::Troubleshooting' is the general troubleshooting
guide, while platform-specific troubleshooting hints
live in their labelled sub-document (e.g., Win32
hints are gathered in 'lib/DBD/Oracle/Troubleshooting/Win32.pod').
Trying to find an ORACLE_HOME
Your DYLD_LIBRARY_PATH env var is set to ''
The ORACLE_HOME environment variable is not set and I couldn't guess it.
It must be set to hold the path to an Oracle installation directory
on this machine (or a machine with a compatible architecture).
See the appropriate troubleshooting guide for your OS for more information.
ABORTED!
-> N/A
-> FAIL Configure failed for DBD-Oracle-1.80. See /Users/username/.cpanm/work/1608142485.48272/build.log for details.
I've read here that ORACLE_HOME
should be set to the value of the directory that contains the /bin
directory but I can't find any /bin
.
Solution 1:[1]
macOS is always changing, but on Mojave I installed Instant Client from the DMGs and then did:
brew install perl
ln -s $HOME/Downloads/instantclient_19_8 $HOME/instantclient
export DYLD_LIBRARY_PATH=$HOME/instantclient
cpan -i -T DBI
cpan -i -T DBD::Oracle
In general, never set ORACLE_HOME for Instant Client. (It can cause the wrong config files to be read). ORACLE_HOME is used for a 'full' database or full client installation, not for Instant Client. However some installers still reference the variable to find build files, so you will need it - at least at build time. DBD::Oracle will internally search for Instant Client and use $HOME/instantclient if $ORACLE_HOME isn't set.
macOS has gradually removed the usefulness of DYLD_LIBRARY_PATH, since it isn't propagated to subshells. This means it can't reliably be used. On Mojave I found I could alternatively copy the Instant Client libraries to $HOME/lib/ and didn't need to set DYLD_LIBRARY_PATH.
Side note: if you're using DBD::Oracle you don't need the Instant Client ODBC package.
Solution 2:[2]
Christopher Jones answer was not enough for me (macOS Monterey 12.2, Apple M1 Pro). The installation stopped with
./Oracle.h:37:10: fatal error: 'oci.h' file not found
To fix this, installation of Oracle SDK Package was required https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html#ic_osx_inst
Second comment:
export DYLD_LIBRARY_PATH=$HOME/instantclient
does not work (see Bash variable of name starting with 'DYLD' is not loaded into environment: bug or feature? )
==================================================
But this is not the end-of-the-problem. The installed DBD::Oracle can not be used. It fails:
Can't load '/Users/myname/.perlbrew/libs/perl-5.34.1@eien6/lib/perl5/darwin-2level/auto/DBD/Oracle/Oracle.bundle'
for module DBD::Oracle: dlopen(/Users/myname/.perlbrew/libs/perl-5.34.1@eien6/lib/perl5/darwin-2level/auto/DBD/Oracle/Oracle.bundle, 0x0001):
symbol not found in flat namespace '_OCIAttrGet' at
/Users/myname/perl5/perlbrew/perls/perl-5.34.1/lib/5.34.1/darwin-2level/DynaLoader.pm line 197.
Is this related to the MacOS SIP mechanism ? How to use DBD::Oracle ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Christopher Jones |
Solution 2 |