方法:
临时提权
sudo su
输入密码
vi /etc/profile
export JAVA_6_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
export JAVA_HOME=$JAVA_6_HOME
alias jdk8=’export JAVA_HOME=$JAVA_8_HOME’
alias jdk6=’export JAVA_HOME=$JAVA_6_HOME’
保存后新开终端窗口,执行java -version
java version “1.6.0_65”
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
输入jdk8将切换到java_home为jdk8的环境