Mac修改环境变量

Mac系统的环境变量,加载顺序为:

  • /etc/profile
  • /etc/paths
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile
  • ~/.bashrc

当然/etc/profile/etc/paths是系统级别的,系统启动就会加载,后面几个是当前用户级的环境变量。后面3个按照从前往后的顺序读取,如果~/.bash_profile文件存在,则后面的几个文件就会被忽略不读了,如果~/.bash_profile文件不存在,才会以此类推读取后面的文件。~/.bashrc没有上述规则,它是bash shell打开的时候载入的。

设置PATH的语法都为:

export PATH=$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

修改系统的环境变量

推荐方式是修改/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

比如把jdk10变成jdk8

打开Sublime Text,修改/etc/profile

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home"

保存(需要输入密码)

你可能感兴趣的:(Mac修改环境变量)