After JDK8 GA, the small partners like to rush, have been eager to experience a Java8 lambda and other new features, but the current Java enterprise application of the main version is JDK6, JDK7. Therefore, I need to have jdk8,jdk7,jdk6 on my computer at the same time. JDK6 and JDK7 mainly do some product code verification, as well as play some of their own open-source projects, JDK8 is purely early adopters, who called us a hate programmer.
Target
At the command line, you can easily switch to the corresponding Java version by command ' Jdk6 ', ' jdk7 ', ' jdk8 ', and the default initial setting is Jdk7.
Practices
1. Install all the JDK first:
* Mac comes with JDK6, installed in directory:/system/library/java/javavirtualmachines/1.6.0.jdk/.
* Jdk7,jdk8 will need to download and install the corresponding version on the Oracle website. The default path for your own JDK installation is:/LIBRARY/JAVA/JAVAVIRTUALMACHINES/JDK1.8.0.JDK
2. Configure the path to Java_home in the bash configuration file in the user directory BASHRC:
Shell Code
- 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 _7_home
3. Create the alias command to dynamically switch Java_home configuration
Shell Code
- Alias jdk8=' export java_home= $JAVA _8_home '
- Alias jdk7=' export java_home= $JAVA _7_home '
- Alias jdk6=' export java_home= $JAVA _6_home '
Authentication
Shell Code
- Cnxnliu:versions xnliu$ java-version
- Java version "1.6.0_65"
- Java (TM) SE Runtime Environment (build 1.6.0_65-b14-462-11m4609)
- Java HotSpot (TM) 64-bit Server VM (build 20.65-b04-462, Mixed mode)
- Cnxnliu:versions xnliu$ Jdk8
- Cnxnliu:versions xnliu$ java-version
- Java version "1.8.0"
- Java (TM) SE Runtime Environment (build 1.8. 0-b132)
- Java HotSpot (TM) 64-bit Server VM (Build 25.0-b70, Mixed mode)
- Cnxnliu:versions xnliu$
Reference: Http://ningandjiao.iteye.com/blog/2045955?utm_source=tuicool
Install multiple versions of the JDK at the same time under Mac