This article is intended to help some students who use Macs switch the JDK.
Recently, some people around frequently asked this question, that is, after installing multiple versions of the Mac, do not know how to switch, and there is little on the internet to solve the problem, so this article will lead you to solve this problem. The level is limited, we all forgive!
1. The directory structure of the JDK on the MAC differs from Windows and requires the installation of Apple's javaforosx2013-004.dmg, or JDK1.6, to install the subsequent versions of the JDK correctly after the installation package has been installed successfully.
2. After installing Apple's JDK1.6, the following directory organization is created under the/system/library/java directory:
Extensions
Javavirtualmachines
Support
and create the following directory structure under the/system/library/frameworks/javavm.framework directory:
Classes
Commands
Frameworks
Home
JavaVM
Libraries
Resources
Versions
3. Install subsequent versions of the JDK
Now you can install JDK1.7 and JDK1.8 on your Mac, and after the installation is complete, there are 1.7 and 1.8 installation directories in the/library/java/javavirtualmachines directory:
Jdk1.7.0_10.jdk
Jdk1.8.0.jdk
4. Next you can run the command: java-version to view the current JDK version
5. Identify different versions of Java_home
After installing Apple's JDK1.6, the system will set the JAVA_HONE environment variable to the current default JDK path when booting, and if you want to switch the current JDK, just switch the java_home environment variable, then our question is how to determine Java_ Home value, now we have to use the/usr/libexec directory in the Mac Java_home program, Java_home can determine the different versions of the JDK's home path, if directly run Java_home will show the current JDK home path, If you want to see different versions of the JDK path, you can use this:
# JAVA_HOME-V 1.8
/library/java/javavirtualmachines/jdk1.8.0.jdk/contents/home
If 1.7, the command is:
# java_home-v 1.7
/library/java/javavirtualmachines/jdk1.7.0_10.jdk/contents/home
6. Switch JDK
After you have identified the different versions of the JDK path, the main thing is to switch the JDK, as long as the value of the JAVA_HOME environment variable is set to the corresponding JDK version of the home path. The temporary practice is to:
# export java_home= ' java_home-v 1.8 '
If you want to set the default java_home at boot time, add this command to your startup script. such as/ETC/BASHRC or/etc/profile.
In fact, the JDK switch is so simple!!
This article is from the "10969631" blog, please be sure to keep this source http://10979631.blog.51cto.com/10969631/1720670
Java version switching on mac (switch Java on Mac)