Install Oracle’s Instant Client 12.1 and Oracle SQL Plus on Ubuntu 12.04 x64

To begin with, Oracle’s instant client is a free client software for connecting to, well, Oracle databases.

We’re not going to use alien here to convert .rpm packages but will install from zip archives instead.

Register and Download Instant Client Packages

We will need to register to be able to download the software. Registration is free of charge.

Go to the download page. Once registered, we need to download the following packages:

instantclient-basic-linux.x64-12.1.0.1.0.zip
instantclient-sqlplus-linux.x64-12.1.0.1.0.zip

Install Software

Move both zip files to /opt/ directory and change to it afterwards:

# cd /opt

Unzip archives:

# unzip instantclient-basic-linux.x64-12.1.0.1.0.zip
Archive:  instantclient-basic-linux.x64-12.1.0.1.0.zip
  inflating: instantclient_12_1/BASIC_README
  inflating: instantclient_12_1/adrci
  inflating: instantclient_12_1/genezi
  inflating: instantclient_12_1/libclntsh.so.12.1
  inflating: instantclient_12_1/libclntshcore.so.12.1
  inflating: instantclient_12_1/libnnz12.so
  inflating: instantclient_12_1/libocci.so.12.1
  inflating: instantclient_12_1/libociei.so
  inflating: instantclient_12_1/libocijdbc12.so
  inflating: instantclient_12_1/libons.so
  inflating: instantclient_12_1/liboramysql12.so
  inflating: instantclient_12_1/ojdbc6.jar
  inflating: instantclient_12_1/ojdbc7.jar
  inflating: instantclient_12_1/uidrvci
  inflating: instantclient_12_1/xstreams.jar
# unzip instantclient-sqlplus-linux.x64-12.1.0.1.0.zip
Archive:  instantclient-sqlplus-linux.x64-12.1.0.1.0.zip
  inflating: instantclient_12_1/SQLPLUS_README
  inflating: instantclient_12_1/glogin.sql
  inflating: instantclient_12_1/libsqlplus.so
  inflating: instantclient_12_1/libsqlplusic.so
  inflating: instantclient_12_1/sqlplus

Rename the default instantclient_12_1 directory to sqlplus:

# mv instantclient_12_1 sqlplus

Create a log folder:

# mkdir -p /opt/sqlplus/log/diag/clients

This helps to avoid getting /home/$USER/oradiag_root folders created due to the following error:

Directory does not exist for read/write [/opt/sqlplus/log] [/opt/sqlplus/log/diag/clients]

Configure

Add /opt/sqlplus to the shared library path LD_LIBRARY_PATH:

# export LD_LIBRARY_PATH=/opt/sqlplus:${LD_LIBRARY_PATH}

Also add /opt/sqlplus to the PATH variable to avoid using absolute/relative paths:

# export PATH=/opt/sqlplus:${PATH}

Set SQLPATH /opt/sqlplus so glogin.sql can be found:

# export SQLPATH=/opt/sqlplus:${SQLPATH}

Note that no ORACLE_HOME or ORACLE_SID environment variables need to be set for SQL Plus Instant Client.

Now, we want those variables to be persistent across system reboots. We also want those variables to be set for all users when they log in to the system so they can use sqlplus client without a need to export variables.

Listed below are the files that are processed when a regular user logs in (when Bash is invoked as an interactive login shell):

/etc/profile
~/.bash_profile
~/.bash_login
~/.profile

The first file that is processed when logging in is /etc/profile. This file sets file sets the global environment for all users.

The user’s ~/.bash_profile is run only if it exists. If the file is missing, bash then looks for a ~/.bash_login to run. If that file is also missing, bash finally tries to run ~/.profile.

It is likely that ~/.bash_profile and ~/.bash_login files may not exits on a system.

In this case the best way to set global environment variables for all users is to put them into /etc/profile. Do:

# echo "export LD_LIBRARY_PATH=/opt/sqlplus:${LD_LIBRARY_PATH}" >>/etc/profile
# echo "export PATH=/opt/sqlplus:${PATH}" >>/etc/profile
# echo "export SQLPATH=/opt/sqlplus:${SQLPATH}" >>/etc/profile

Try to connect to a locally accessible database:

# sqlplus 'root@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.1.3) (PORT=1521))(CONNECT_DATA=(SID=test)))'

SQL*Plus: Release 12.1.0.1.0 Production on Sun Feb 16 13:46:57 2014
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Enter password:

Connected to: Oracle Database 11g Release 11.2.0.3.0 - 64bit Production

SQL>

Troubleshooting

sqlplus: error while loading shared libraries: libaio.so.1

If you get the following error when running sqlplus:

sqlplus: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

Make sure you have the libaio1 library installed:

# apt-get update && apt-get install libaio1

error: ORA-21561: OID generation failed

If you get this error:

ERROR: ORA-21561: OID generation failed

Check that your hostname is correctly defined inside /etc/hostname and /etc/hosts:

# echo "ubuntu" > /etc/hostname
# head -n1 /etc/hosts
127.0.0.1 localhost ubuntu

3 thoughts on “Install Oracle’s Instant Client 12.1 and Oracle SQL Plus on Ubuntu 12.04 x64

Leave a Reply

Your email address will not be published. Required fields are marked *