# Can't load oracle oci8 libs

**URL:** <https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425>\
**Category:** Deployment\
**Created:** [September 24, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425 "2008-09-24T18:54:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [September 24, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/1 "2008-09-24T18:54:01Z")

</div>

Hi,

I’m deploying a Rails app with a Mongrel Cluster in Red Hat Linux. It  
communicates with an Oracle database on another machine.

I tested ruby-oci8 from the command line, and that worked fine:

$ ruby -r oci8 -e “OCI8.new(‘user’, ‘password’, ‘???.???.?.?/  
xe’).exec(‘SELECT BLAH BLAH BLAH) do |r| puts r.join(’ | '); end”

I was then able to run my application on both servers of a Mongrel  
Cluster, started from the command line, like this:

$ mongrel\_cluster\_ctl start

But when I try to make a service out of my cluster, the two Mongrel  
servers start, but my application logs the following error message:

Oracle/OCI libraries could not be loaded: libclntsh.so.11.1: cannot  
open shared object file: No such file or directory - /usr/local/lib/  
ruby/site\_ruby/1.8/i686-linux/oci8lib.so

This library file exists and has read permission for all, and the path  
to it is set in LD\_LIBRARY\_PATH.

I’d appreciate if someone could help me out on this. Thanks,

Chris.

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [September 30, 2008, 8:28pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/2 "2008-09-30T20:28:09Z")

</div>

Hi Fritzek,

I apologize for the delay, but my boss keeps hitting me with tasks  
that are always more important than the previous…

Anyway, this is how I installed the Oracle Instant Client:

[chris@localhost ~]$ sudo rpm -i oracle-instantclient-  
basic-11.1.0.1-1.i386.rpm  
Password:  
[chris@localhost ~]$ sudo rpm -i oracle-instantclient-  
devel-11.1.0.1-1.i386.rpm  
Password:  
[chris@localhost ~]$ sudo rpm -i oracle-instantclient-  
sqlplus-11.1.0.1-1.i386.rpm

The Symbolic link was automatically created for libclntsh.so:

[chris@localhost ~]$ cd /usr/lib/oracle/11.1.0.1/client/lib  
[chris@localhost lib]$ ls -l lib\*  
lrwxrwxrwx 1 root root 17 Sep 10 09:53 libclntsh.so -\>  
libclntsh.so.11.1  
-rw-r–r-- 1 root root 35295891 Aug 1 2007 libclntsh.so.11.1  
…

And these files have all the permissions. I don’t know what else to  
look at.

Chris.

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [September 25, 2008, 1:28am UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/3 "2008-09-25T01:28:02Z")

</div>

Hi Chris  
I’ve found this:

* * *

Hi Kubo,  
Thanks. Actually I export LD\_LIBRARY\_PATH for non-root user but not  
for  
root. Now it works following these steps:

- su - root
- rpm -ivh oracle-instantclient-basic-11.1.0.1-1.rpm  
oracle-instantclient-devel-11.1.0.1-1.rpm (download  
link\<[http://www.oracle.com/technology/tech/oci/instantclient/](http://www.oracle.com/technology/tech/oci/instantclient/)  
index.html\>;  
or  
install oracle full client)
- export LD\_LIBRARY\_PATH=/usr/lib/oracle/  
11.1.0.1/client/lib:$LD\_LIBRARY\_PATH
- cd /usr/lib/oracle/11.1.0.1/client/lib
- ln -s libclntsh.so.11.1 libclntsh.so
- gem install ruby-oci8

* * *

Might be this helps. Its a pain with libclntsh.so since version 7 of  
oracle.  
Fritzek

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [October 1, 2008, 2:02pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/4 "2008-10-01T14:02:47Z")

</div>

Here’s more : I started a mongrel\_cluster by hand (the application  
works fine) and compared it to the one started as a service. According  
to “ps -ef”, they’re identical, EXCEPT for the PRIORITY level (5 by  
hand, 0 as a service). Could this be causing my problem?

Mongrel\_Cluster started by hand:

* * *

[chris@localhost log]$ ps -ef | grep mongrel  
chris 4781 1 5 05:55 ? 00:00:02 /usr/local/bin/ruby /  
usr/local/bin/mongrel\_rails start -d -e production -a 0.0.0.0 -c /home/  
chris/kitry/FDS\_Server --user chris --group chris -p 4001 -P log/  
mongrel.4001.pid -l log/mongrel.4001.log  
chris 4784 1 5 05:55 ? 00:00:02 /usr/local/bin/ruby /  
usr/local/bin/mongrel\_rails start -d -e production -a 0.0.0.0 -c /home/  
chris/kitry/FDS\_Server --user chris --group chris -p 4002 -P log/  
mongrel.4002.pid -l log/mongrel.4002.log

Mongrel\_Cluster started as a service:

* * *

[chris@localhost ~]$ ps -ef | grep mongrel  
chris 2759 1 0 06:04 ? 00:00:02 /usr/local/bin/ruby /  
usr/local/bin/mongrel\_rails start -d -e production -a 0.0.0.0 -c /home/  
chris/kitry/FDS\_Server --user chris --group chris -p 4001 -P log/  
mongrel.4001.pid -l log/mongrel.4001.log  
chris 2762 1 0 06:04 ? 00:00:02 /usr/local/bin/ruby /  
usr/local/bin/mongrel\_rails start -d -e production -a 0.0.0.0 -c /home/  
chris/kitry/FDS\_Server --user chris --group chris -p 4002 -P log/  
mongrel.4002.pid -l log/mongrel.4002.log

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [October 2, 2008, 2:40am UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/5 "2008-10-02T02:40:22Z")

</div>

Chris,

What script are you using to start mongrel\_cluster as a service? My  
guess is that the script in question runs as root, and then switches  
to the proper user prior to starting the mongrel cluster. Anytime a  
process becomes a user, the environment it runs in is considerably  
more “crippled” than usual. Things like .bashrc, for example, won’t  
get sourced, so the environment ends up missing lots of important  
details. The environment that you see logged in as chris and the  
environment that the service sees when it is logged in as chris are  
two very different things.

A good start would be to look at the top of the init script that is  
getting executed for the service. Depending on whether it calls /bin/  
bash or /bin/sh there are two different sets of files that you might  
need to edit to provide an appropriate environment. (This is assuming  
that your default shell is bash, and that sh is a symlink to bash.)  
Look in the “INVOCATION” section of the bash man page for more  
details.

Hope that helps.

–  
Alex Malinovich  
Director of Deployment Services

PLANET ARGON, LLC  
design // development // hosting

> **[Planet Argon](https://www.planetargon.com)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.the-love-shack.net](http://www.the-love-shack.net) [blog]

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [October 3, 2008, 8:28am UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/6 "2008-10-03T08:28:43Z")

</div>

Actually, I’ve had to do both… So my problem was actually solved by  
adding LD\_LIBRARY\_PATH to the mongrel\_rails script.

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [October 22, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/7 "2008-10-22T15:04:40Z")

</div>

I’ve been busy too… sorry for the late reply.

Anyway, I’m already doing what you suggest, that is: exporting the  
LD\_LIBRARY\_PATH from within a shell script in /etc/profile.d. And  
although the environment variable is indeed set when I open a terminal  
window, it is not set when the mongrel\_rails processes are started as  
a service. So if I remove the related line from the mongrel\_rails  
script, they are no longer able to access the database.

Anyone has an idea how to set an environment variable that is visible  
to a service upon startup?

Thanks,

Chris.

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [March 4, 2010, 6:06pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/8 "2010-03-04T18:06:56Z")

</div>

set it in /etc/enviroment

without export, just var\_name=/path/to/dir

gers32 wrote:

> I’ve been busy too… sorry for the late reply.
> 
> Anyway, I’m already doing what you suggest, that is: exporting the  
> LD\_LIBRARY\_PATH from within a shell script in /etc/profile.d. And  
> although the environment variable is indeed set when I open a terminal  
> window, it is not set when the mongrel\_rails processes are started as  
> a service. So if I remove the related line from the mongrel\_rails  
> script, they are no longer able to access the database.
> 
> Anyone has an idea how to set an environment variable that is visible  
> to a service upon startup?
> 
> Thanks,
> 
> Chris.

---

<div class="post-metadata">

**Author:** ![gers32](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@gers32](https://www.ruby-forum.com/u/gers32)\
**Post date:** [October 2, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/cant-load-oracle-oci8-libs/149425/9 "2008-10-02T15:42:40Z")

</div>

Thank you both for your help. I ended up setting my LD\_LIBRARY\_PATH in  
a new file called /etc/profile.d/oracle\_libs.sh, and that solved my  
problem.

Setting the environment variable inside the mongrel\_rails script also  
worked, but the solution above allows me to use SQL\*Plus as well.

Cheers,

Chris.
