只可以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/environment
cat /etc/profile
cat /etc/bash.bashrc
cat /etc/profile.d/test.sh
cat ~/.profile
cat ~/.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/environment
chmod -v u+w /etc/profile # 如果/etc/profile文件不可编辑,需要修改为可编辑
vim /etc/profile
chmod -v u+w /etc/profile # 如果/etc/profile文件不可编辑,需要修改为可编辑
vim /etc/bash.bashrc
vim /etc/profile.d/test.sh
vim ~/.profile
vim ~/.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/bin
export PATH=/home/uusama/mysql/bin:$PATH
$PATH的意思是包括以前的
记得运行一下
source /etc/environment
source /etc/profile
source /etc/bash.bashrc
source /etc/profile.d/test.sh
source ~/.profile
source ~/.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"