
只可以root操作
| 命令 | 解释 |
|---|---|
export |
命令显示当前系统定义的所有环境变量 |
echo $PATH |
命令输出当前的PATH环境变量的值 |
export
echo $PATH
| 顺序 | 文件 | 名字 | 级别 | 生效时间 | 生效期限 | 生效范围 | 系统开机执行顺序 | 用户登录执行顺序 | bash shell 打开执行顺序 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | /etc/environment | 大环境 | 系统级 | 运行source /etc/environment生效 |
永久有效 | 所有用户 | 1 | 1 | |
| 2 | /etc/profile | 轮廓 | 系统级 | 运行source /etc/profile生效 |
永久有效 | 所有用户 | 2 | 2 | |
| 3 | /etc/bash.bashrc | 栏杆 | 系统级 | 运行source /etc/bash.bashrc生效 |
永久有效 | 所有用户 | 1 | ||
| 4 | /etc/profile.d/test.sh | 轮廓(自定义的) | 系统级 | 运行source /etc/profile.d/test.sh生效 |
永久有效 | 所有用户 | 3 | ||
| 5 | ~/.profile | 轮廓 | 用户级 | 运行source ~/.profile生效 |
永久有效 | 当前用户(就在当前用户的文件夹) | 4 | ||
| 6 | ~/.bashrc | 栏杆 | 用户级 | 运行source ~/.bashrc生效 |
永久有效 | 当前用户(就在当前用户的文件夹) | 2 | ||
| / | 无文件直接终端修改 | 临时 | 用户级 | 立即生效 | 终端关闭失效 | 当前用户 |
查看命令:用:冒号分隔cat /etc/environmentcat /etc/profilecat /etc/bash.bashrccat /etc/profile.d/test.shcat ~/.profilecat ~/.bashrc
cat /etc/environment

cat /etc/profile

cat /etc/bash.bashrc

cat /etc/profile.d/test.sh
cat ~/.profile

cat ~/.bashrc

修改命令 vim修改:chmod -v u+w /etc/profile # 如果/etc/profile文件不可编辑,需要修改为可编辑vim /etc/environmentchmod -v u+w /etc/profile # 如果/etc/profile文件不可编辑,需要修改为可编辑vim /etc/profilechmod -v u+w /etc/profile # 如果/etc/profile文件不可编辑,需要修改为可编辑vim /etc/bash.bashrcvim /etc/profile.d/test.shvim ~/.profilevim ~/.bashrc
修改内容:# 建议用这种PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/python3.7.9/bin"后来加的::/usr/local/python3.7.9/bin# 在最后一行加上export PATH=$PATH:/home/uusama/mysql/bin# 无文件直接终端修改:export PATH=$PATH:/home/uusama/mysql/binexport PATH=/home/uusama/mysql/bin:$PATH$PATH的意思是包括以前的
记得运行一下source /etc/environmentsource /etc/profilesource /etc/bash.bashrcsource /etc/profile.d/test.shsource ~/.profilesource ~/.bashrc
cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
换行解释一下
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"