Mac OSX 10.9以后系统就自带了Java 6的环境,路径在:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
如果想要安装升级到Java 7的环境,步骤如下:
/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home
在.bash_profile文件中添加:
export JAVA_HOME=$(/usr/libexec/java_home) export PATH=$JAVA_HOME/bin:$PATH
需要说明的是Mac OSX 10.5之后苹果就建议设置$JAVA_HOME变量到/usr/libexec/java_home
$java -version java version "1.7.0_60" Java(TM) SE Runtime Environment (build 1.7.0_60-b19) Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode) # 查看系统安装的java版本 $/usr/libexec/java_home -V Matching Java Virtual Machines (3): 1.7.0_60, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_60.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 # 返回系统安装的java最高版本 $/usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home