Linux - 设置 Path

一、查看现有 Path

echo $PATH

二、修改 Path

1. 临时修改,关闭连接后失效

export PATH=/usr/local/bin:$PATH

2. 永久修改当前用户

vim ~/.bashrc 
// 在最后一行添上:
export PATH=/usr/local/bin:$PATH

关闭保存,执行 source ~/.bashrc 命令生效

3. 全局修改,所有用户生效

vim /etc/profile
// 在最后一行添上:
export PATH=/usr/local/bin:$PATH

关闭保存,执行 source /etc/profile 命令生效

三、每次启动自动加载 .bashrc

.bash_profile 文件中自动加载 .bashrc 文件。

vim ~/.bash_profile

在文件内部输入:

# 加载.bashrc文件
if test -f .bashrc ; then
source .bashrc 
fi

参考