/etc/profile
|- System wide environment and startup programs, for login setup
|- 用于登录设置的全系统环境和启动程序
/etc/bashrc
|- System wide functions and aliases
|- 系统范围的函数和别名
/etc/profile.d/
|- It's much better to create a custom.sh shell script in /etc/profile.d/ to make custom changes to your environment, as this will prevent the need for merging in future updates.
|- 最好在/etc/profile.d/中创建一个custom.Shell脚本,以便对环境进行自定义更改,因为这将避免在将来的更新中合并。
~/.bash_profile
|- User specific environment and startup programs
|- 用户特定环境和启动程序
~/.bashrc
|- User specific aliases and functions
|- 用户特定别名和函数
系统启动时加载 /etc/profile -> 内部加载 /etc/profile.d/ 路径下的*.sh脚本;
用户登录时加载 ~/.bash_profile -> 内部加载 ~/.bashrc -> 内部加载 /etc/bashrc -> 内部加载 /etc/profile.d/ 路径下的*.sh脚本;
用户退出时加载 ~/.bash_logout ;
结论:
在 /etc/profile 中配置系统变量;
在 ~/.bash_profile 中配置用户变量;
如何配置:
如果你要使用Python3作为python的默认版本,你需要修改一下 bashrc 文件,增加一行alias参数
alias python='/usr/local/bin/python3.7'
由于CentOS 7建议不要动/etc/bashrc文件,而是把用户自定义的配置放入/etc/profile.d/目录中,具体方法为
vi /etc/profile.d/python.sh
输入alias参数 alias python="/usr/local/bin/python3.7",保存退出
如果非root用户创建的文件需要注意设置权限
chmod 755 /etc/profile.d/python.sh
重启会话使配置生效
source /etc/profile.d/python.sh
首先注意usr 指 Unix System Resource,而不是User
然后通常/usr/bin下面的都是系统预装的可执行程序,会随着系统升级而改变
/usr/local/bin目录是给用户放置自己的可执行程序的地方,推荐放在这里,不会被系统升级而覆盖同名文件
如果两个目录下有相同的可执行程序,谁优先执行受到PATH环境变量的影响,比如我的一台服务器的PATH变量为
echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/dean/bin
这里/usr/local/bin优先于/usr/bin,