在linux命令行中
- 直接在linux的命令行中更新了profile文件,profile文件中更新了path变量,然后保存退出。发现未生效,那是因为没有
source ~/.profile或source /etc/profile - 如果你执行了第一步,生效了,但重启之后又无效了,那需要在重启之后,再执行一次
source ~/.profile或source /etc/profile - 如果你不想每次重启都进行上一步的操作那就执行这条命令
echo "source /etc/profile" >> /root/.bashrc,将source /etc/profile追加到/root/.bashrc文件末尾(.bashrc文件中的脚本,每次启动都会被执行一次),或者echo "source /etc/profile" >> ~/.bashrc
在自定义的shell脚本中
解决shell脚本中"source /etc/profile"重载配置文件不生效的问题-腾讯云开发者社区-腾讯云 (tencent.com)
在docker的Dockerfile中
docker 每次都得source /etc/profile以及如何查看Docker容器环境变量、向容器传递环境变量_容器source 环境变量-CSDN博客
参考资料
/etc/profile文件使用source不能全局生效的解决方法_/etc/profile环境变量不生效-CSDN博客
解决shell脚本中"source /etc/profile"重载配置文件不生效的问题-腾讯云开发者社区-腾讯云 (tencent.com)