brew install sqlplus

Gee, that didn’t work.

For those of you wondering about the title of this post, I’m referring to the brew package manager for Mac OS — a nice utility for installing Unix-like packages on Mac OS similar to how yum / apt-get can be used on Linux.

I particularly like the way brew uses /usr/local and symlinks for clean installations of software without messing up the standard Mac paths.

Unfortunately, there isn’t a brew “formula” for installing sqlplus and the instant client libraries (and probably never will be due to licensing restrictions), but we can come close using ideas from Oracle ACE Ronald Rood and his blog post Oracle Client 11gR2 (11.2.0.3) for Apple Mac OS X (Intel).

Go there now and read up through “unzipping the files” — after that, return here and we’ll see how to simulate a brew installation.

organize the software

mkdir -p /usr/local/Oracle/product/instantclient/11.2.0.4.0/bin
mkdir -p /usr/local/Oracle/product/instantclient/11.2.0.4.0/lib
mkdir -p /usr/local/Oracle/product/instantclient/11.2.0.4.0/jdbc/lib
mkdir -p /usr/local/Oracle/product/instantclient/11.2.0.4.0/rdbms/jlib
mkdir -p /usr/local/Oracle/product/instantclient/11.2.0.4.0/sqlplus/admin

Change to the instantclient_11_2 directory where the files were extracted, and execute the following commands to place them into our newly created directories:

mv ojdbc* /usr/local/Oracle/product/instantclient/11.2.0.4.0/jdbc/lib/
mv x*.jar /usr/local/Oracle/product/instantclient/11.2.0.4.0/rdbms/jlib/
mv glogin.sql /usr/local/Oracle/product/instantclient/11.2.0.4.0/sqlplus/admin/
mv *dylib* /usr/local/Oracle/product/instantclient/11.2.0.4.0/lib/
mv *README /usr/local/Oracle/product/instantclient/11.2.0.4.0/
mv * /usr/local/Oracle/product/instantclient/11.2.0.4.0/bin/

While these commands place the files where we want them, we’ll need to do a few more things to make them usable. If you’re using brew already, /usr/local/bin will be in your PATH and you won’t need to add it. We’ll mimic what brew does and symlink sqlplus into /usr/local/bin.

cd /usr/local/bin
ln -s ../Oracle/product/instantclient/11.2.0.4.0/bin/sqlplus sqlplus

This will put sqlplus on our path, but we still need to set the environment variables for things like ORACLE_BASE, ORACLE_HOME and the DYLD_LIBRARY_PATH. Ronald sets them manually and then adds them to his .bash_profile, but I wanted to mimic some of the brew packages and have a .sh file to set variables from /usr/local/share.
To do so, I created another directory underneath /usr/local/Oracle to hold my .sh file:

cd /usr/local/Oracle/product/instantclient/11.2.0.4.0
mkdir -p share/instantclient
cd /usr/local/share
ln -s ../Oracle/product/instantclient/11.2.0.4.0/share/instantclient/ instantclient

Now I can create an instantclient.sh file and place it in /usr/local/Oracle/product/instantclient/11.2.0.4.0/share/instantclient/ with the content I want in my environment.

$ cat /usr/local/share/instantclient/instantclient.sh 
export ORACLE_BASE=/usr/local/Oracle
export ORACLE_HOME=$ORACLE_BASE/product/instantclient/11.2.0.4.0
export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
export TNS_ADMIN=$ORACLE_BASE/admin/network

Once I have this file in place, I can edit my .bash_profile file and add the following line:

source /usr/local/share/instantclient/instantclient.sh

Open up a new Terminal window and voila! A working sqlplus installation that mimics a brew package install!

Posted in Uncategorized. No Comments »

Leave a Reply

Posting code can be a pain. To make sure your code doesn't get eaten, you may want to pre-format it first by using HTML Encoder