How to set the environmental variable LD_LIBRARY_P

2019-01-01 06:42发布

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?

10条回答
君临天下
2楼-- · 2019-01-01 06:44

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.

查看更多
若你有天会懂
3楼-- · 2019-01-01 06:48

The file .bash_profile is only executed by login shells. You may need to put it in ~/.bashrc, or simply logout and login again.

查看更多
明月照影归
4楼-- · 2019-01-01 06:49

Alternatively you can execute program with specified library dir:

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

Read more here.

查看更多
不再属于我。
5楼-- · 2019-01-01 06:50

For some reason no one has mentioned the fact that the bashrc needs to be re-sourced after editing. You can either log out and log back in (like mentioned above) but you can also use the commands: source ~/.bashrc or . ~/.bashrc.

查看更多
路过你的时光
6楼-- · 2019-01-01 07:01

Put export LD_LIBRARY_PATH=/usr/local/lib in ~/.bashrc [preferably towards end of script to avoid any overrides in between, Default ~/.bashrc comes with many if-else statements]

Post that whenever you open a new terminal/konsole, LD_LIBRARY_PATH will be reflected

查看更多
回忆,回不去的记忆
7楼-- · 2019-01-01 07:02

Add

LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"

to /etc/environment

See the Ubuntu Documentation.

CORRECTION: I should take my own advice and actually read the documentation. It says that this does not apply to LD_LIBRARY_PATH: Since Ubuntu 9.04 Jaunty Jackalope, LD_LIBRARY_PATH cannot be set in $HOME/.profile, /etc/profile, nor /etc/environment files. You must use /etc/ld.so.conf.d/.conf configuration files.* So user1824407's answer is spot on.

查看更多
登录 后发表回答