可以使用工具命令“/usr/libexec/java_home”来定位JAVA_HOME:
定位JAVA:
/usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_25, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
另外可以使用-V选项列出所有版本的JAVA_HOME:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
1.7.0_45, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
1.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
配置JAVA_HOME:
$ cat ~/.profile
JAVA_HOME=`/usr/libexec/java_home`
export JAVA_HOME
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
$ source ~/.profile
$java
时间: 2024-11-25 10:04:09