#确认jdk版本
/usr/libexec/java_home
#会得到下面信息 (different versions are displayed differently)
/library/java/javavirtualmachines/jdk1.7.0_60.jdk/contents/home
#上面是1. Version 7 JDK, you can use the-V ID to get other installed versions of the JDK, such as: The 1.6 version of the JDK that comes with the system
/usr/libexec/java_home-v ' 1.6* '
#会得到下面信息 (Mac OS X 10.9.4 comes with 1.6JDK)
/system/library/java/javavirtualmachines/1.6.0.jdk/contents/home
Get the above information and start creating a configuration file
#创建. Bash_profile configuration file (Skip this step if you already have the file)
Touch ~/.bash_profile
#vim编辑. bash_profile file
Vim ~/.bash_profile
#如果不习惯vim命令就使用自带的文本编辑器打开
Open ~/.bash_profile
#将下面内容输入到. Bash_profile Inside
# mac default JDK 6 (Mac default comes with a jdk6 version) export java_6_home=$ (/usr/libexec/java_home-v 1.6) # set JDK 7export java_7_home=$ (/usr/ Libexec/java_home-v 1.7) #默认JDK 7export java_home= $JAVA _7_home#alias command dynamically switch JDK version alias jdk6= "Export java_home= $JAVA _6_ HOME "Alias jdk7=" Export java_home= $JAVA _7_home "
#输入完成后保存执行下面命令
#重新执行. bash_profile file
SOURCE ~/.bash_profile
#切换直接终端输入jdk6或jdk7来切换jdk版本
Get JDK version, edit. Bash_profile
. bash_profile Configuration file Contents
All commands, JDK version switch from: http://blog.sina.com.cn/s/blog_63fea2670102uwpt.html
Mac system different Java version switch