本文摘自:https://blog.csdn.net/lichangzhen2008/article/details/44959563
>cd /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home >./bin/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)
JDK7之后,安装目录比较规范化了,按着版本号在/Library/Java/JavaVirtualMachines/
下自动建立子目录
/Library/Java/JavaVirtualMachines>ls -lrt
total 0
drwxr-xr-x 3 root wheel 102 11 2 15:22 jdk1.7.0_67.jdk
drwxr-xr-x 3 root wheel 102 11 3 14:58 jdk1.7.0_71.jdk
drwxr-xr-x 3 root wheel 102 4 9 13:44 jdk1.8.0_40.jdk
安装和下载同JDK7
每次安装完后,自动更新/usr/libexec/java_home
/Users/lcz>/usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
~/.bash_profile
,没有的话创建vim ~/.bash_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_71.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
alias jdk6="export JAVA_HOME=$JAVA_6_HOME" #编辑一个命令jdk6,输入则转至jdk1.6
alias jdk7="export JAVA_HOME=$JAVA_7_HOME" #编辑一个命令jdk8,输入则转至jdk1.8
alias jdk8="export JAVA_HOME=$JAVA_8_HOME" #编辑一个命令jdk8,输入则转至jdk1.8
export JAVA_HOME=`/usr/libexec/java_home` #最后安装的版本,这样当自动更新时,始终指向最新版本
>. .bash_profile
>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
>jdk6
>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)
>jdk7
>java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
标 题:Mac安装多个JDK版本并设置环境变量