Installing Oracle Instant Client and SQL*Plus on OSX
Step 1: Download
You will need to download at least 3 files from oracle. In order to do so, you may need to register as an Oracle developer, or log in. The three files you need are the “basic”, “SDK” and “sqlplus” files for instantclient. They can all be found on the Oracle website.
- instantclient-basic-macosx-<version>.zip
- instantclient-sdk-macosx-<version>.zip
- instantclient-sqlplus-macosx-<version>.zip
Download them to a temporary folder on your machine.
Step 2: Uncompress and Copy Files
Uncompress the files to the /op/oracle/ folder on your machine. You will have to first create the folder:
sudo mkdir -p /opt/oracle
Then uncompress the zip files in to that folder. You can do this from your temp directory with this command:
cd /opt/oracle sudo unzip ~/Downloads/oracle/instantclient-\*.zip
After you uncompress the files, you can create an alias for the instantclient folder. This will enable you to upgrade later, simply by changing where the link points.
sudo ln -s instantclient_11_2/ instantclient
Now some of the dylib files include versions in their filenames, but some programs such as SQL*Plus do not look for the versioned file, they look for the generic filename. So to resolve that problem, we need to also create links for them.
sudo ln -s libclntsh.dylib.11.1 libclntsh.dylib sudo ln -s libocci.dylib.11.1 libocci.dylib
So up to this point, we now have all the files on our machine, and are ready to start configuring oracle client.
Step 3: Configure Oracle
You can configure oracle for all users of the system (and that is part of the reason we placed all the files in /opt/oracle instead of the users home folder.) But this configuration is per user, not system wide. Modify the users .bash_profile, and add the following lines:
# oracle export ORACLE_HOME=/opt/oracle/instantclient export DYLD_LIBRARY_PATH=$ORACLE_HOME export LD_LIBRARY_PATH=$ORACLE_HOME export NLS_LANG=AMERICAN_AMERICA.UTF8 export TNS_ADMIN=$HOME/etc export PATH=$PATH:$ORACLE_HOME
You can set the NLS_LANG to be whatever is right for your situation, I choose AMERICAN_AMERICA.UTF8 since that is correct for me. You will also note I did not set the TNS_ADMIN folder to be /etc, the default location, instead I placed it in the users home directory. This is up to you, I find it easier to have each user manage their own TNS_NAMES. Finally it adds the executables to the path.
Once that is finished you can source the file, or open another terminal window, and then you will be able to run SQL*Plus.
source ~/.bash_profile sqlplus
You should be greeted by the version of the release that you just installed.
To configure your tns_names.ora file, if needed, you should create the directory etc in your home folder, and ad the file.
mkdir ~/etc touch tnsnames.ora
Using your favorite editor, edit the tnsnames.ora file. For more information on configuring the file, check this link.
After doing this a few times, I made a bash file that can do most of the work for you. You have to run this script from the folder after you have downloaded the oracle zip files.