How to set the environmental variable LD_LIBRARY_PATH in linux

singha picture singha · Nov 17, 2012 · Viewed 930k times · Source

I have first executed the command: export LD_LIBRARY_PATH=/usr/local/lib

Then I have opened .bash_profile file: vi ~/.bash_profile. In this file, I put:

LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH

Then if the terminal is closed and restarted, typing echo $LD_LIBRARY_PATH displays no result.

How to set the path permanently?

Answer

user1824407 picture user1824407 · Nov 17, 2012

You should add more details about your distribution, for example under Ubuntu the right way to do this is to add a custom .conf file to /etc/ld.so.conf.d, for example

sudo gedit /etc/ld.so.conf.d/randomLibs.conf

inside the file you are supposed to write the complete path to the directory that contains all the libraries that you wish to add to the system, for example

/home/linux/myLocalLibs

remember to add only the path to the dir, not the full path for the file, all the libs inside that path will be automatically indexed.

Save and run sudo ldconfig to update the system with this libs.