首先执行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不会显示任何结果。

如何永久设置路径?


当前回答

由于某种原因,没有人提到bashrc在编辑后需要重新来源的事实。您可以退出并重新登录(如上所述),但也可以使用命令:source ~/。Bashrc或。~ / . bashrc。

其他回答

我在Mint 15到17中做以下工作,也适用于ubuntu服务器12.04及以上:

sudo vi /etc/bash.bashrc 

滚动到底部,并添加:

export LD_LIBRARY_PATH=.

所有用户都添加了环境变量。

或者你也可以用指定的库目录执行程序:

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

点击这里阅读更多。

在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盒子里为我工作的。

你应该添加更多关于你的发行版的细节,例如在Ubuntu下,正确的做法是在/etc/ld.so.conf中添加一个自定义的.conf文件。例如,D。

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

例如,在文件内部,您应该写入包含希望添加到系统中的所有库的目录的完整路径

/home/linux/myLocalLibs

记住只添加目录的路径,而不是文件的完整路径,该路径内的所有库将被自动索引。

保存并运行sudo ldconfig,使用这些库更新系统。

转到主文件夹并编辑.profile 把下面这行放在末尾 export LD_LIBRARY_PATH=<您的路径> 保存并退出。 执行此命令 sudo ldconfig