Mac 系统的环境变量,加载顺序为:
/etc/profile
/etc/paths
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
前两个是系统级别的,系统启动就会加载。后面 3 个是当前用户级别的环境变量。后面几个按照从前往后的顺序读取,如果 ~/.bash_profile 存在,则后面的几个文件就会被忽略不读了,如果 .bash_profile 不存在,才会依次读取垢面的文件。~/.bashrc没有上述规则,它是bash shell打开的时候载入的。
添加环境变量示例
修改 ~/.bashrc 文件,添加环境变量
export DEPLOY_PATH="10.10.11.11::rsync_id"
载入
source ~/.bashrc
常见问题解决
1、安装zsh 导致环境变量设置无效,每次打开窗口需要执行source
解决办法:
修改 vim ~/.zshrc
文件增加如下代码
if [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi