Install multiple versions of JDK at the same time under Mac

copy from:https://gist.github.com/ameizi/2d9908e8b6df9078904a

Install multiple versions of JDK at the same time under Mac

The JDK6 that comes with the Mac is installed in the directory: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/under.

For JDK7 and JDK8, you need to download and install the corresponding version from Oracle's official website. The default path of the JDK installed by yourself is:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk

1. Configure the path of JAVA_HOME in the bash configuration file .bashrc in the user directory:

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

JAVA_HOME2. Create a configuration for dynamic switching of the alias command

alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias jdk7='export JAVA_HOME=$JAVA_7_HOME'
alias jdk6='export JAVA_HOME=$JAVA_6_HOME'

3. Verification

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$

or use http://www.jenv.be/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326079201&siteId=291194637