1)、
# macOS默认 JDK 6(Apple 自己维护的JDK)
export JAVA_6_HOME="/usr/libexec/java_home -v 1.6"
#设置JDK7、JDK8、JDK9、JDK10
export JAVA_7_HOME="/usr/libexec/java_home -v 1.7"
export JAVA_8_HOME="/usr/libexec/java_home -v 1.8"
export JAVA_9_HOME="/usr/libexec/java_home -v 9"
export JAVA_10_HOME="/usr/libexec/java_home -v 10"
#alias取别名
alias jdk6="export JAVA_HOME=$JAVA_6_HOME"
alias jdk7="export JAVA_HOME=$JAVA_7_HOME"
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk9="export JAVA_HOME=$JAVA_9_HOME"
alias jdk10="export JAVA_HOME=$JAVA_10_HOME"
2)、
//查看默认jdk的安装路径
/usr/libexec/java_home
//查看jdk 1.8的安装路径
/usr/libexec/java_home -v 1.8
输出:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
//查看jdk 1.6的安装路径
/usr/libexec/java_home -v 1.6
输出:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home