Skip to content

Instantly share code, notes, and snippets.

@mmasashi
Last active May 1, 2021 10:38
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save mmasashi/4fe95399494cbfd3c89171192cae4ba0 to your computer and use it in GitHub Desktop.
Save mmasashi/4fe95399494cbfd3c89171192cae4ba0 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
mv sdk /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/lib/
mv ojdbc* /usr/local/Oracle/product/instantclient/$ORACLE_VERSION/jdbc/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_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"
@anandsinha07
Copy link

hello..
when i run sqlplus, it promoted as "Enter username ".
which username and password to be entered ?

@jimzucker
Copy link

Hi, take a look at my fork, we need ORACLE_VERSION in the instantclient.sh and I added some error checking... it would be great if you merged them I can't see how to do a pull request.

@immilev
Copy link

immilev commented Dec 18, 2017

Why move the sdk into lib? sqlplus does not require it, and tools that expect the standard installation of instantclient break.

@abezhinaru
Copy link

Thanks you a lot, it's works for me!

@deepanshurana
Copy link

I don't have any file named 'instantclient.sh' and where to paste the 'install.sh' file?

@Rammstein78
Copy link

For me it does not work on my MacOS. THe install.sh script says this:

"Error on line 18 /usr/local/bin folder not found" and
"Error on line 23 /usr/local/share folder not found"

I added the following right before going into the respective directories:
mkdir -p /usr/local/bin
cd /usr/local/bin

But again nothing works for me. Should I execute install.sh at step 3 ?

@bozhyk
Copy link

bozhyk commented Oct 26, 2018

Damn, it is just wasting time, instruction is not working
install.sh just says:
ln: libclntsh.dylib: File exists
/usr/local/share/instantclient/instantclient.sh is not found

@elulcao
Copy link

elulcao commented Oct 27, 2018

Hello all,

Instead of mv'ing the files we should just cp'ing all the files.
Refresh the Symlinks with -sfn flag.
Preserve the "/opt/Oracle/product/" directory, like installing the DB or GRID.

I tried this and it worked as expected :

`#!/bin/bash

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

cp -R sdk /opt/Oracle/product/$ORACLE_VERSION/lib/
cp -R ojdbc* /opt/Oracle/product/$ORACLE_VERSION/jdbc/lib/
cp -R x*.jar /opt/Oracle/product/$ORACLE_VERSION/rdbms/jlib/
cp -R glogin.sql /opt/Oracle/product/$ORACLE_VERSION/sqlplus/admin/
cp -R dylib /opt/Oracle/product/$ORACLE_VERSION/lib/
cp -R *README /opt/Oracle/product/$ORACLE_VERSION/
cp -R * /opt/Oracle/product/$ORACLE_VERSION/bin/

echo "Creating SymLinks"
ln -sfn /opt/Oracle/product/$ORACLE_VERSION/bin/sqlplus /usr/local/bin/sqlplus
ln -sfn /opt/Oracle/product/$ORACLE_VERSION/lib/libclntsh.dylib.12.1 libclntsh.dylib

echo "Creating env variables"
echo "
export ORACLE_BASE=/opt/Oracle/
export ORACLE_HOME=$ORACLE_BASE/product/$ORACLE_VERSION
export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
export OCI_DIR=$DYLD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_BASE/admin/network
" > /opt/Oracle/instantclient.sh

echo "Done!"
echo
echo "Next step: Add the following code to your ~/.bashrc"
echo "source /opt/Oracle/instantclient.sh"`

HackBook-Pro:~ test$ date;env | grep -i oracle
Fri Oct 26 20:54:22 CDT 2018
OCI_DIR=/opt/Oracle//product/12.2.0.1.0/lib
ORACLE_BASE=/opt/Oracle/
TNS_ADMIN=/opt/Oracle//admin/network
ORACLE_HOME=/opt/Oracle//product/12.2.0.1.0
HackBook-Pro:~ test$ date; sqlplus
Fri Oct 26 20:54:32 CDT 2018

SQL*Plus: Release 12.2.0.1.0 Production on Fri Oct 26 20:54:33 2018

Copyright (c) 1982, 2017, Oracle. All rights reserved.

Enter user-name:

@elulcao
Copy link

elulcao commented Oct 27, 2018

hello..
when i run sqlplus, it promoted as "Enter username ".
which username and password to be entered ?

You need to add the complete string connection:

sqlplus /@':/'

ie:
sqlplus system/Welcome1#@'10.10.10.10:1521/ORCL1.test.mydomain'

@ajeesh2705
Copy link

It's waste of time, the instruction is really confusing

@moisoto
Copy link

moisoto commented Nov 22, 2019

This script was of great help when I installed 12.2 a while back. I had to do it manually since the script was kind of crude and some things were wrong (like putting SDK files on lib directory).

Now that 19.3 is out I decided to upgrade, and this time I made some scripts which I think must work on every Mac.

You can check them here if you want to use them: Oracle Instant Client 9.3 Install Scripts for macOS

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