Monday, July 21, 2008

Sqlplus on a Mac with Oracle Instant Client

One of the things any Oracle developer uses is sqlplus, but getting it to work on Mac OS-X is not quite as easy as on Windows. Follow these steps to install sqlplus on your Mac.

1. Download the Oracle Instant Client Zip files:
  • Instant Client Package - Basic
  • Instant Client Package - SQL*Plus
  • Instant Client Package - JDBC Supplement (Optional)
  • Instant Client Package - SDK (Optional)
2. Launch the Terminal and unzip the files to instantclient10_2.

unzip instantclient-basic-macosx-10.2.0.4.0.zip
unzip instantclient-sqlplus-macosx-10.2.0.4.0.zip
unzip instantclient-jdbc-macosx-10.2.0.4.0 #Optional
unzip instantclient-sdk-macosx-10.2.0.4.0 #Optional

3. Move the directory to where you want it. I put mine in /usr/local/oracle/instantclient_10_2.

sudo mkdir /usr/local/oracle/
sudo mv instantclient_10_2 /usr/local/oracle/

4. Then go to this directory and make symbolic links for dynamic libraries.

sudo ln -s libclntsh.dylib.10.1 libclntsh.dylib
sudo ln -s libocci.dylib.10.1 libocci.dylib

5. I reccomend creating a tnsnames.ora file where you add all your connection details. I placed mine in /usr/local/oracle/network/admin.

Example of a tnsnames.ora file:

IDENTIFIER =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = userid.myhosteddb.net)(PORT = 1521))
)
(CONNECT_DATA = (SID = odb))
)

6. Then you need to set up necessary environment variables. I added mine to my .bash_profile script so they are alway's set when I run the terminal.

In your home folder you can type:


vi .bash_profile

And then add the following lines at the end of the file (Make sure you set the PATH correctly otherwise sqlplus won't run):

export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_10_2"
export SQLPATH="/usr/local/oracle/instantclient_10_2"
export TNS_ADMIN="/usr/local/oracle/network/admin"
export NLS_LANG="AMERICAN_AMERICA.UTF8"
export PATH=$PATH:$DYLD_LIBRARY_PATH

7. You should now be able to run sqlplus. Close the terminal and re-lunch it. Now run:

sqlplus [username]/[password]@[service]

8. Sqlplus should now run and look something like this:

4 comments:

Amor said...

How could I save after pasting this ?

"export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_10_2"
export SQLPATH="/usr/local/oracle/instantclient_10_2"
export TNS_ADMIN="/usr/local/oracle/network/admin"
export NLS_LANG="AMERICAN_AMERICA.UTF8"
export PATH=$PATH:$DYLD_LIBRARY_PATH"

Marinus Snyman said...

You should be able to use ":wq" followed by the "Return Key"
If that makes sense?

You can also see more on vi commands here:
http://www.cs.colostate.edu/helpdocs/vi.html

sap support packs said...

Its not very easy to install Sqlplus with Oracle client on Mac as I have tried to do so many times. I will follow the steps that you have listed to install Sqlplus, may be I get succeeded this time.

Marinus Snyman said...

Please try. These steps worked for me many times..