linux下如何设置环境变量LD_LIBRARY_PATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13428910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set the environmental variable LD_LIBRARY_PATH in linux
提问by singha
I have first executed the command: export LD_LIBRARY_PATH=/usr/local/lib
我首先执行了命令: export LD_LIBRARY_PATH=/usr/local/lib
Then I have opened .bash_profile
file: vi ~/.bash_profile
.
In this file, I put:
然后我打开了.bash_profile
文件:vi ~/.bash_profile
. 在这个文件中,我放了:
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.
然后,如果终端关闭并重新启动,则键入echo $LD_LIBRARY_PATH
不会显示任何结果。
How to set the path permanently?
如何永久设置路径?
回答by Some programmer dude
The file .bash_profile
is only executed by login shells. You may need to put it in ~/.bashrc
, or simply logout and login again.
该文件.bash_profile
仅由登录 shell 执行。您可能需要将其放入~/.bashrc
,或者只是注销并再次登录。
回答by Anshul
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]
把export LD_LIBRARY_PATH=/usr/local/lib
在~/.bashrc
[优选地朝向脚本的端,以避免两者之间的任何替代,预设~/.bashrc
带有许多if-else
语句]
Post that whenever you open a new terminal/konsole, LD_LIBRARY_PATH
will be reflected
发布,每当您打开新的终端/konsole,LD_LIBRARY_PATH
都会反映
回答by user1824407
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
您应该添加有关您的发行版的更多详细信息,例如在 Ubuntu 下正确的方法是将自定义.conf
文件添加到/etc/ld.so.conf.d
,例如
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.
保存并运行sudo ldconfig
以使用此库更新系统。
回答by Methusael Murmu
You could try adding a custom script, say myenv_vars.sh
in /etc/profile.d
.
您可以尝试添加自定义脚本,例如 myenv_vars.sh
在/etc/profile.d
.
cd /etc/profile.d
sudo touch myenv_vars.sh
sudo gedit myenv_vars.sh
Add this to the empty file, and save it.
将此添加到空文件中,然后保存。
export LD_LIBRARY_PATH=/usr/local/lib
Logout and login, LD_LIBRARY_PATH
will have been set permanently.
注销和登录,LD_LIBRARY_PATH
将被永久设置。
回答by MrUser
Add
添加
LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"
LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"
to /etc/environment
到 /etc/environment
See the Ubuntu Documentation.
请参阅Ubuntu 文档。
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 Hymanalope, 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.
更正:我应该接受我自己的建议并实际阅读文档。它说这不适用于 LD_LIBRARY_PATH:由于 Ubuntu 9.04 Jaunty Hymanalope,LD_LIBRARY_PATH 不能在 $HOME/.profile、/etc/profile 和 /etc/environment 文件中设置。您必须使用 /etc/ld.so.conf.d/.conf 配置文件。* 所以 user1824407 的回答是正确的。
回答by Johnnyb
I do the following in Mint 15 through 17, also works on ubuntu server 12.04 and above:
我在 Mint 15 到 17 中执行以下操作,也适用于 ubuntu 服务器 12.04 及更高版本:
sudo vi /etc/bash.bashrc
scroll to the bottom, and add:
滚动到底部,然后添加:
export LD_LIBRARY_PATH=.
All users have the environment variable added.
所有用户都添加了环境变量。
回答by nbroeking
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
.
出于某种原因,没有人提到 bashrc 需要在编辑后重新获取资源这一事实。您可以注销并重新登录(如上所述),但您也可以使用以下命令:source ~/.bashrc
或. ~/.bashrc
。
回答by K15.Multik
Alternatively you can execute program with specified library dir:
或者,您可以使用指定的库目录执行程序:
/lib/ld-linux.so.2 --library-path PATH EXECUTABLE
回答by Ariel Monaco
Keep the previous path, don't overwrite it:
保留之前的路径,不要覆盖它:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/
You can add it to your ~/.bashrc:
你可以将它添加到你的 ~/.bashrc 中:
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/' >> ~/.bashrc
回答by singingsingh
- Go to the home folder and edit .profile
Place the following line at the end
export LD_LIBRARY_PATH=<your path>
Save and Exit.
Execute this command
sudo ldconfig
- 转到主文件夹并编辑 .profile
将以下行放在最后
export LD_LIBRARY_PATH=<your path>
保存并退出。
执行这个命令
sudo ldconfig