MAC的环境变量
mac系统的环境变量加载顺序为:
/etc/profile
/etc/paths
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
其中前两个是系统级别的,系统启动就会加载。
后面几个是当前用户级别的环境变量,每次系统开机后需要重新设置后才会生效。
后面3个按照从上往下的顺序读取,如果~/.bash_profile
文件存在,则后面的几个文件就会被忽略不读了,如果~/.bash_profile
文件不存在,才会以此类推读取后面的文件。~/.bashrc
没有上述规则,它是bash shell打开的时候载入的。
修改环境变量
修改PATH的语法为:
export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>
修改系统环境变量
推荐修改etc/profile
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home"
export JAVA_HOME
CLASS_PATH="$JAVA_HOME/lib"
export ANDROID_HOME=/Users/chenli4/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=$JAVA_HOME/bin:$PATH
修改当前用户的环境变量
推荐修改~/.bash_profile
export ANDROID_HOME=/Users/chenli4/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:/Users/chenli4/Library/Android/sdk/platform-tools
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH