首先执行export LD_LIBRARY_PATH=/usr/local/lib命令
然后我打开了.bash_profile文件:vi ~/.bash_profile。 在这个文件中,我放了:
LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
然后,如果终端被关闭并重新启动,输入echo $LD_LIBRARY_PATH不会显示任何结果。
如何永久设置路径?
首先执行export LD_LIBRARY_PATH=/usr/local/lib命令
然后我打开了.bash_profile文件:vi ~/.bash_profile。 在这个文件中,我放了:
LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
然后,如果终端被关闭并重新启动,输入echo $LD_LIBRARY_PATH不会显示任何结果。
如何永久设置路径?
当前回答
或者你也可以用指定的库目录执行程序:
/lib/ld-linux.so.2 --library-path PATH EXECUTABLE
点击这里阅读更多。
其他回答
将export LD_LIBRARY_PATH=/usr/local/lib放入~/中。bashrc[最好是在脚本的末尾,以避免任何覆盖之间,默认~/。Bashrc带有许多if-else语句]
发布当您打开一个新的终端/konsole时,LD_LIBRARY_PATH将被反映
由于某种原因,没有人提到bashrc在编辑后需要重新来源的事实。您可以退出并重新登录(如上所述),但也可以使用命令:source ~/。Bashrc或。~ / . bashrc。
在Ubuntu 20.04 Linux中,这并不是显而易见的。
我将尝试让它变得简单,让那些正在拔头发的人,就像我使用Ubuntu 20.04.3 Linux一样。
首先确定库文件文件夹所在的路径。在我的例子中,*。所以我使用的文件位于一个名为libs的文件夹中,这个文件夹在我的Ubuntu盒子中的路径是/usr/lib
所以现在我想添加路径/usr/lib到LD_LIBRARY_PATH,这样当我在我的Ubuntu终端运行echo $LD_LIBRARY_PATH时,我将能够看到路径/usr/lib,如下所示;
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
下面是我使用的步骤
Open terminal in Ubuntu 20.04 Linux box Change path to /etc/ld.so.conf.d/ by running cd /etc/ld.so.conf.d/ Create a file with a *.conf extension at the end with a text editor like e.g. vim or gedit in my case I created it as follows sudo gedit my_project_libs.conf Inside the .conf file that I created named my_project_libs.conf I added the path to my libs by adding this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib Thereafter, I then run gedit ~/.bash_profile to open the ~/.bash_profile file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want included in LD_LIBRARY_PATH I also ran gedit ~/.bashrc to open the ~/.bashrc file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want included in LD_LIBRARY_PATH When you are done adding the line in step 5, save and close. In your terminal, type the following sudo ldconfig and press enter on your keyboard. Close all your open terminals that you were using then open a new terminal session and run echo $LD_LIBRARY_PATH If you see the path you added is echoed back, you did it right.
在我的例子中,这就是我在新打开的Ubuntu终端会话中运行echo $LD_LIBRARY_PATH时看到的:/usr/lib
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
这就是我如何让它在我的Ubuntu 20.04.3 Linux盒子里为我工作的。
.bash_profile文件仅由登录shell执行。你可能需要把它放在~/中。Bashrc,或者简单地登出并再次登录。
我在Mint 15到17中做以下工作,也适用于ubuntu服务器12.04及以上:
sudo vi /etc/bash.bashrc
滚动到底部,并添加:
export LD_LIBRARY_PATH=.
所有用户都添加了环境变量。