注意
- Linux的环境变量是保存在变量PATH中(windows 也是保存在PATH中),可通过命令
echo $PATH
输出查看 - Linux环境变量值之间是通过冒号分隔的( : )
其格式为:
PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>
临时添加环境变量PATH:
可通过 export
命令,如
export PATH=/usr/local/nginx/sbin/:$PATH
,将/usr/local/nginx/sbin/
目录临时添加到环境变量中
当前用户永久添加环境变量:
编辑.bashrc
文件 vim ~/.bashrc
文件末尾添加:export PATH="/usr/local/nginx/sbin/:$PATH"
然后执行:source ~/.bashrc
所有用户永久添加环境变量:
编辑/etc/profile
文件 vim /etc/profile
文件末尾添加:export PATH="/usr/local/nginx/sbin/:$PATH"
然后执行:source /etc/profile