首先执行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不会显示任何结果。
如何永久设置路径?
当前回答
您可以尝试添加一个自定义脚本,例如在/etc/ profiles .d.中添加myenv_vars.sh
cd /etc/profile.d
sudo touch myenv_vars.sh
sudo gedit myenv_vars.sh
将其添加到空文件中,并保存它。
export LD_LIBRARY_PATH=/usr/local/lib
注销和登录时,LD_LIBRARY_PATH将被永久设置。
其他回答
.bash_profile文件仅由登录shell执行。你可能需要把它放在~/中。Bashrc,或者简单地登出并再次登录。
你应该添加更多关于你的发行版的细节,例如在Ubuntu下,正确的做法是在/etc/ld.so.conf中添加一个自定义的.conf文件。例如,D。
sudo gedit /etc/ld.so.conf.d/randomLibs.conf
例如,在文件内部,您应该写入包含希望添加到系统中的所有库的目录的完整路径
/home/linux/myLocalLibs
记住只添加目录的路径,而不是文件的完整路径,该路径内的所有库将被自动索引。
保存并运行sudo ldconfig,使用这些库更新系统。
在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'在默认情况下只用于LOGIN shell。
如果您正在从桌面GUI启动和关闭终端,那么您可能正在寻找的bash配置文件是'~/。Bashrc ',它是启动交互式、非登录shell时默认的源文件。
https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc
保持之前的路径,不要覆盖它:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/
你可以把它添加到你的~/.bashrc:
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/' >> ~/.bashrc