Skip to main content

How to add shared libraries to Linux's system library path

Sometimes in Linux when you install a new software package the instructions tell you to add a directory of shared libraries to your $LD_LIBRARY_PATH environment variable in your .bashrc.

You may have noticed that if you then create a shortcut icon on your desktop to this application it won't start because it can't find the libraries.
A typical solution is to write a wrapper shell script to set the LD_LIBRARY_PATH and then call that application.

Well, I've discovered how to add them to your system's library path allowing all environments to access them. Note: There are differences between Debian and Ubuntu (the two flavours of Linux that I'm familiar with).

Ubuntu
Create a new file in /etc/ld.so.conf.d/ called .conf

Edit the file and add a line per directory of shared libraries (*.so files), it will look something like:
/usr/lib/APPLICATION/lib
Reload the list of system-wide library paths:
sudo ldconfig
Debian
Edit /etc/ld.so.conf

Add a line per directory of shared libraries (*.so files) to the bottom of the file, it will look something like:
/usr/X11R6/lib
/usr/lib/APPLICATION/lib
Reload the list of system-wide library paths:
ldconfig
If you run your new application it should now work fine without you having to set any LD_LIBRARY_PATH environment variables.
If you still have problems you can obtain a list of the libraries that are on the system path by re-running the ldconfig command in verbose mode:
ldconfig -v

Technorati Tags: , , , ,

Comments

Anonymous said…
Hmmm, seems cool.

Joe joestain13@yahoo.com
Kasper said…
Hi Andrew,

And now the other way around:
I want to run an application but without a specif library. The application runs fine when I rename/remove the library. But removing the library completely is to drastic for me.

Can I use ldconfig, ld.conf, etc. to do this?
If so, how?


Cheers,
Kasper
Andrew Beacock said…
Kasper,
I'm sorry to say that I'm not sure how to solve your issue! You can exclude whole directories from the LD_LIBRARY_PATH but no don't know of a way to exclude a particular one.

I think the rename option is probably the best so that you could always resurrect it if another application required it.

If you find a good solution please let me know!
Anonymous said…
Thank you for this post.

I was having problems using a 3rd party shared library and adding the .conf file with the correct directory worked!

(Using Ubuntu)
Anonymous said…
The library path could be placed in any file, whose name ends with ".conf", inside /etc/ld.so.conf.d/.
OneWorld said…
Hi there,
My god I've been digging around for hours to run this application, I followed all the procedures above, but I don't understand where to make these changes as suggested in http://www.bcsoftnet.com/doc.htm

----
The Environmnet variable LD_LIBRARY_PATH must setup to the Oracle Library.
TNS_ADMIN and ORACLE_HOME variable also need to setup either one or both.

example for bash shell:
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
----

Is it working for anyone, please guide me.

thanks,
Andrew Beacock said…
OneWorld, Hi there glad you found my blog - I'm not linked with that Insite Developer software just looks like they liked my shared libraries article.

You see the lines starting "export ..." - they need to be added to the .bashrc or .profile file of the user that is trying to run them. If you are trying to run it from a graphical desktop such as Gnome or KDE then you either need to follow my ideas above or write a little shell script to add the variables in first.

Good luck!
Anonymous said…
nice tip
Anonymous said…
This little tip saved me a world of hurt. Thank-you
Anonymous said…
Thank you.
Anonymous said…
Thank you.
Johnny Bravo said…
Hi Andrew,

This is really nice post.

I have created one shared library which is plugin for pidgin and it depends on libjava.so, libjvm.so
So I have created .conf file under /etc/ld.so.conf.d/ containing
/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386
/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/i386/server

I did sudo ldconfig but still it is not able to locate the libjava.so when i start the pidgin application from
desktop shortcut.

It works fine when i put this in LD_LIBRARY_PATH and start pidgin from terminal.

Any idea what is wrong with my configuration?

I am using Ubuntu 10.10
Mitch said…
Thanks Abeacock! This was helpful!
Arseniew said…
That really helped me, thank you for sharing!
Anonymous said…
Sheer genius! Many thanks. Been tracking a problem caused by this for a day or two and this helped!!! Many thanks.
Anonymous said…
Sheer genius. Thanks for sharing this ... it helped as a tracked a problem caused by this for the last day or so ... Many thanks!
Unknown said…
Actually creating a ".conf" file doesn't work. The file has to have a non-empty name, such as "a.conf".
amitkv said…
It really worked for me ! Thanks aton !
Unknown said…
Does anyone know a fix for this problem in windows, thanks in advanced
Unknown said…
Do you know of a way i can fix this in windows