1, 下载jdk jdk-8u74-macosx-x64.dmg (jdk-8u20-macosx-x64.dmg)
2,配置环境变量
进入/Users/xxx
vi ~/.bash_profile
单版本
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH:.
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
source ~/.bash_profile
多版本
export JAVA_HOME_8=/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home
export JAVA_HOME_17=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
export JAVA_HOME=$JAVA_HOME_8
alias jdk8="export JAVA_HOME=$JAVA_HOME_8"
alias jdk17="export JAVA_HOME=$JAVA_HOME_17"
export PATH=$JAVA_HOME/bin:$PATH:.
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
验证
java
javac
java -version