@xtccc
2016-07-03T10:31:56.000000Z
字数 1153
阅读 2045
Java
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.0_91, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
1.7.0_75, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
可以看到, 我的MAC上现在装有1.7和1.8两个版本的JDK,并且当前默认JDK的JAVA_HOME路径为
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
用命令 java -verion
$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
也可以直接查看当前的JAVA_HOME:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
现在,MAC上安装了1.7和1.8两个版本的JDK,且默认的JDK版本是1.8。我想将默认的JDK改为1.7,该怎么办呢?
最简单的方法是将JAVA_HOME
指向1.7版本的JDK家目录:
$ export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
$ java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)
这里,我们只要指定JDK1.7的major version就可以了。