installing Oracle Instantclient on Linux without setting environment variables?

36,239

Solution 1

Oracle's instantclient installation instructions specify that the user set LD_LIBRARY_PATH. This is very troublesome to manage for multiple users.

To use the instantclient without setting any environment variables:

Download the instantclient distribution from oracle.com. For doing non-java software development, you will need (assuming Oracle 10.2):

instantclient-basic-linux-x86_64-10.2.0.4.0.zip
instantclient-sdk-linux-x86_64-10.2.0.4.0.zip
instantclient-sqlplus-linux-x86_64-10.2.0.4.0.zip

Unzip the three files. This will give you a directory

instantclient_10_2/

Copy the files to /usr, which is one of the default places the dynamic loader searches.

sudo cp instantclient_10_2/sdk/include/*.h /usr/include
sudo cp instantclient_10_2/sqlplus         /usr/bin
sudo cp instantclient_10_2/*.so*           /usr/lib

If you use tnsnames.ora, copy it to /etc, which is the default global place the oracle runtime searches.

sudo cp tnsnames.ora /etc

Test with

/usr/bin/sqlplus scott/tiger@myoracle

Solution 2

Add the library path to /etc/ld.so.conf, then run /sbin/ldconfig. You don't need to set LD_LIBRARY_PATH for libraries installed in standard locations like /usr/lib because these locations are already configured in /etc/ld.so.conf.

Solution 3

You could of course rename sqlplus to sqlplus.real and make a wrapper script:

#!/bin/sh

if [ "$LD_LIBRARY_PATH" = "" ]
then
        LD_LIBRARY_PATH=/what/ever
else
        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/what/ever
fi

export LD_LIBRARY_PATH

exec sqlplus.real ${1+"$@"}

Solution 4

Oracle's instructions regarding setting the LD_LIBRARY_PATH are suboptimal.

On ELF platforms like Linux or Solaris there is really no need to require setting the LD_LIBRARY_PATH because the correct library search path (a.k.a. runpath) can be written into the binary, at build-time, relative to the location of the binary. Thus, with such binaries, the runtime linker is always able to find the packaged libraries, even if the installed subtree is copied around.

Unfortunately, Oracle doesn't create the Linux 'Instant Client' binaries like that. But, it is possible to fix them with patchelf.

For example:

patchelf --set-rpath '$ORIGIN/..' /path/to/instantclient_11_2/sdk/proc
patchelf --set-rpath '$ORIGIN'    /path/to/instantclient_11_2/sqlplus
patchelf --set-rpath '$ORIGIN'    /path/to/instantclient_11_2/libclntsh.so.11.1

After those changes the runtime linker is able to find all needed libraries without any LD_LIBRARY_PATH environment variable.

On Solaris there is elfedit - but IIRC at least some Oracle DB packages for Solaris already come with a sufficient runpath. One can verify that via e.g. elfdump /path/to/sqlplus | grep PATH.

For more details on elfedit and other good alternatives to LD_LIBRARY_PATH (that don't involve changing the binary itself) see also my article LD_LIBRARY_PATH considered harmful.

Solution 5

or you can try using this command

Linux

sqlplus user/pass@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port_number)))(CONNECT_DATA=(SID=sid)))'

Windows

sqlplus user/pass@"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port_number)))(CONNECT_DATA=(SID=sid)))"

so you don't need the tnsnames.ora

Share:
36,239
Mark Harrison
Author by

Mark Harrison

I'm a Software Engineer at Google where I work on machine learning planning systems. From 2001-2015 I was the Pixar Tech Lead of the Data Management Group. My 50-year charter was to store and catalog all data and metadata related to the Studio's feature films. This system ("Templar") is in use to this day. From 1997 to 2001 I lived in Beijing, China and was the Chief Software Architect at AsiaInfo, the company that built China's Internet. While there my software was used to grow the China Internet from 200K to 65M users. The last I heard they were at 350M+ users. I studied computer science and worked in Texas for many years. I wrote a couple of computer books... the best one was in print for 20 years. Feel free to drop me a line! [email protected]

Updated on July 27, 2020

Comments