java home mac_在MAC上查找和设置$JAVA_HOME

最近升级了MAC OS,装了JDK7 for mac,在这里下载JDK7 for mac,装完之后发现在默认的路径下找不到JDK7的HOME,如下所示:

$ which java

/usr/bin/java

$ ls -l /usr/bin/java

lrwxr-xr-x 1 root wheel 74 Jan 4 20:24 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions

total 64

lrwxr-xr-x 1 root wheel 10 Jan 4 20:24 1.4 -> CurrentJDK

lrwxr-xr-x 1 root wheel 10 Jan 4 20:24 1.4.2 -> CurrentJDK

lrwxr-xr-x 1 root wheel 10 Jan 4 20:24 1.5 -> CurrentJDK

lrwxr-xr-x 1 root wheel 10 Jan 4 20:24 1.5.0 -> CurrentJDK

lrwxr-xr-x 1 root wheel 10 Jan 4 20:24 1.6 -> CurrentJDK

lrwxr-xr-x 1 root wheel 10 Jan 4 20:24 1.6.0 -> CurrentJDK

drwxr-xr-x 7 root wheel 238 Jan 4 20:25 A

lrwxr-xr-x 1 root wheel 1 Jan 4 20:24 Current -> A

lrwxr-xr-x 1 root wheel 59 Jan 4 20:24 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

可是查看java的版本确实是1.7,如下:

$ java -version

java version "1.7.0_45"

Java(TM) SE Runtime Environment (build 1.7.0_45-b18)

Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

google了一下,发现了这篇文章Important Java Directories on Mac OS X,可以使用工具命令“/usr/libexec/java_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

另外可以使用-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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值