Skip to content

Instantly share code, notes, and snippets.

@jimzucker
Forked from mmasashi/README.md
Last active October 5, 2018 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jimzucker/957b92a9c954eaa30a8c74e7b2f74bd6 to your computer and use it in GitHub Desktop.
Save jimzucker/957b92a9c954eaa30a8c74e7b2f74bd6 to your computer and use it in GitHub Desktop.
Install Oracle instant client (sqlplus) v12.1 on MacOSX

Install Oracle instant client (sqlplus) on MacOSX

  1. Get Oracle instant client for MacOSX
  1. Unarchive downloaded zip files into a same directory
  • ex: $HOME/Downloads/instantclient_12_1
  1. Create install.sh and copy the following code and past it on that file.
  2. Run source /usr/local/share/instantclient/instantclient.sh
  3. Run sqlplus to check if you can run "sqlplus" in any place
  4. Add source /usr/local/share/instantclient/instantclient.sh to your .bashrc
#!/bin/bash
set -e
export ORACLE_VERSION="12.1.0.2.0"
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/bin
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/jdbc/lib
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/rdbms/jlib
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/sqlplus/admin
#ensure we have all of the files we need
if [ ! -f sqlplus ]
then
echo "instantclient-sqlplus not downloaded, exiting...."
exit 1
fi
if [ ! -d sdk ]
then
echo "ERROR: instantclient-sdk not downloaded, exiting...."
exit 1
fi
mv ojdbc* /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/jdbc/lib/
if [ $? -ne 0 ]
then
echo "ERROR: cannot find ojdbc drivers, instantclient-basic not installed, exiting"
exit 1
fi
mv sdk /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib/
mv x*.jar /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/rdbms/jlib/
mv glogin.sql /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/sqlplus/admin/
mv *dylib* /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib/
mv *README /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/
mv * /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/bin/
cd /usr/local/bin
ln -s ../Oracle/product/instantclient/$ORACLE_VERSION/bin/sqlplus sqlplus
cd /usr/local/Oracle/product/instantclient/$ORACLE_VERSION
mkdir -p share/instantclient
cd /usr/local/share
ln -s ../Oracle/product/instantclient/$ORACLE_VERSION/share/instantclient/ instantclient
cd /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib
ln -s libclntsh.dylib.12.1 libclntsh.dylib
echo "
export ORACLE_VERSION=$ORACLE_VERSION
export ORACLE_BASE=/usr/local/Oracle
export ORACLE_HOME=\$ORACLE_BASE/product/instantclient/$ORACLE_VERSION
export DYLD_LIBRARY_PATH=\$ORACLE_HOME/lib
export OCI_DIR=\$DYLD_LIBRARY_PATH
export TNS_ADMIN=\$ORACLE_BASE/admin/network
" > /usr/local/share/instantclient/instantclient.sh
echo "Done!"
echo
echo "Next step: Add the following code to your ~/.bashrc"
echo "source /usr/local/share/instantclient/instantclient.sh"
exit 0
@mehdip2007
Copy link

Hi,
I have created the install.sh file mentioned above and executed it but the following error comes:

➜ instantclient_12_2 sqlplus
dyld: Library not loaded: @rpath/libsqlplus.dylib
Referenced from: /usr/local/bin/sqlplus
Reason: image not found
[1] 8397 abort sqlplus
➜ instantclient_12_2 /usr/local/bin/sqlplus
dyld: Library not loaded: @rpath/libsqlplus.dylib
Referenced from: /usr/local/bin/sqlplus
Reason: image not found
[1] 8403 abort /usr/local/bin/sqlplus
➜ instantclient_12_2 otool -L /usr/local/bin/sqlplus
/usr/local/bin/sqlplus:
@rpath/libsqlplus.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libclntsh.dylib.12.1 (compatibility version 0.0.0, current version 0.0.0)
@rpath/libclntshcore.dylib.12.1 (compatibility version 0.0.0, current version 0.0.0)
@rpath/libnnz12.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
➜ instantclient_12_2 otool -L sqlplus
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: 'sqlplus': No such file or directory

I have followed the steps in the following but no luck .
https://blog.caseylucas.com/2013/03/03/oracle-sqlplus-and-instant-client-on-mac-osx-without-dyld_library_path/
https://blogs.oracle.com/taylor22/sqlplus-and-dyldlibrarypath-on-mac-osx

@mehdip2007
Copy link

issue is fixed.

the problem was since I use zshesll I need to add
export DYLD_LIBRARY_PATH=/usr/local/Oracle/product/instantclient/12.1.0.2.0/lib
in my ~/.zshrc file

@endryha
Copy link

endryha commented Oct 5, 2018

Hi, thank you for the script, I modified it a little so I can easily re-run it multiple times. I had to do so because I had incorrect installation of the sqlplus before and it was reporting errors that it cannot create file links.

The change is following: ln -s -> ln -sf

@endryha
Copy link

endryha commented Oct 5, 2018

#!/bin/bash

set -e
export ORACLE_VERSION="12.1.0.2.0"
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/bin
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/jdbc/lib
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/rdbms/jlib
mkdir -p /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/sqlplus/admin

#ensure we have all of the files we need
if [ ! -f sqlplus ]
then
  echo "instantclient-sqlplus not downloaded, exiting...."
  exit 1
fi

if [ ! -d sdk ]
then
  echo "ERROR: instantclient-sdk not downloaded, exiting...."
  exit 1
fi
mv ojdbc* /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/jdbc/lib/
if [ $? -ne 0 ]
then
  echo "ERROR: cannot find ojdbc drivers, instantclient-basic not installed, exiting"
  exit 1
fi
mv sdk /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib/
mv x*.jar /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/rdbms/jlib/
mv glogin.sql /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/sqlplus/admin/
mv *dylib* /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib/
mv *README /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/
mv * /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/bin/
cd /usr/local/bin
ln -sf ../Oracle/product/instantclient/$ORACLE_VERSION/bin/sqlplus sqlplus

cd /usr/local/Oracle/product/instantclient/$ORACLE_VERSION
mkdir -p share/instantclient
cd /usr/local/share
ln -sf ../Oracle/product/instantclient/$ORACLE_VERSION/share/instantclient/ instantclient
cd /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib
ln -sf libclntsh.dylib.12.1 libclntsh.dylib

echo "
export ORACLE_VERSION=$ORACLE_VERSION
export ORACLE_BASE=/usr/local/Oracle
export ORACLE_HOME=\$ORACLE_BASE/product/instantclient/$ORACLE_VERSION
export DYLD_LIBRARY_PATH=\$ORACLE_HOME/lib
export OCI_DIR=\$DYLD_LIBRARY_PATH
export TNS_ADMIN=\$ORACLE_BASE/admin/network
" > /usr/local/share/instantclient/instantclient.sh

echo "Done!"
echo
echo "Next step:  Add the following code to your ~/.bashrc"
echo "source /usr/local/share/instantclient/instantclient.sh"
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment