export LD_LIBRARY_PATH
LD_LIBRARY_PATH
程序运行时依赖库的位置,默认是
lib
/usr/lib
/usr/local/lib
通过命令export LD_LIBRARY_PATH=path:$LD_LIBRARY_PATH
追加用户库文件路径。
注意事项
通过export
添加的环境变量仅针对当前运行shell生效,退出后被重置,而且重新启动的shell也不会继承。
问题记录
export LD_LIBRARY_PATH=path:$LD_LIBRARY_PATH
sudo ./xxx
cannot open shared object file: No such file or directory
测试发现sudo运行这一步不在当前shell,导致export LD_LIBRARY_PATH=path:$LD_LIBRARY_PATH
无效,
只能sudo LD_LIBRARY_PATH=path:$LD_LIBRARY_PATH ./xxx
才能执行
shell环境测试(Ubuntu 22.04)
$ps
PID TTY TIME CMD
7346 pts/1 00:00:00 bash
7393 pts/1 00:00:00 ps
$sudo ps
PID TTY TIME CMD
7395 pts/2 00:00:00 sudo
7396 pts/2 00:00:00 ps