Coder Perfect

What is the best way to set the environmental variable? LD LIBRARY PATH is a linux variable.

Problem

I started by running the line export LD LIBRARY PATH=/usr/local/lib

Then I ran vi /.bash profile to open the.bash profile file. In this file, I’ve included:

LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH

After that, reopening the terminal and running echo $LD LIBRARY PATH yields no results.

How can I make the trail permanent?

Asked by singha

Solution #1

You should include more information about your distribution; for example, under Ubuntu, you should add a custom.conf file to /etc/ld.so.conf.d.

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

You should write the whole path to the directory that contains all the libraries you want to add to the system, for example, inside the file.

/home/linux/myLocalLibs

Remember to only add the path to the directory, not the whole path to the file; all the libs within that path will be indexed automatically.

To update the system with these libs, save and run sudo ldconfig.

Answered by user1824407

Solution #2

Keep the previous path instead of overwriting it:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/

You can include it in your /.bashrc file:

echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/' >> ~/.bashrc

Answered by Ariel Monaco

Solution #3

Add

to /etc/environment

See the Ubuntu Documentation for further information.

CORRECTION: I should follow my own advise and read the documentation thoroughly. This does not apply to LD LIBRARY PATH, according to the documentation: LD LIBRARY PATH cannot be set in $HOME/.profile, /etc/profile, or /etc/environment files since Ubuntu 9.04 Jaunty Jackalope. The configuration files /etc/ld.so.conf.d/.conf must be used. So user1824407’s response is correct.

Answered by MrUser

Solution #4

Alternatively you can execute program with specified library dir:

/lib/ld-linux.so.2 --library-path PATH EXECUTABLE

Read more here.

Answered by K15.Multik

Solution #5

Login shells are the only ones who run the.bash profile file. It’s possible you’ll need to add it to /.bashrc, or you may simply logout and log back in.

Answered by Some programmer dude

Post is based on https://stackoverflow.com/questions/13428910/how-to-set-the-environmental-variable-ld-library-path-in-linux