安装
因为并非所有用户都用得着 Java ,所以在默认状态下 OS X 不预装 Java , 如果你需要的话可以手动安装.
1. http://support.apple.com/kb/DL1572
到苹果官网下载.
http://support.apple.com/downloads/DL1572/en_US/JavaForOSX2014-001.dmg
2.http://www.oracle.com/technetwor ... ownloads/index.html
到 Oracle 下载最新版的 Java 8 JDK 安装.
安装后在终端输入
1
|
java -version |
如果显示版本就说明安装好了.
如果显示如下, 就说明没安装对,需要重新来过.
1
|
No Java runtime present, requesting install. |
在MAC上查找和设置$JAVA_HOME
可以使用工具命令“/usr/libexec/java_home”来定位JAVA_HOME:
定位JAVA:
1
|
/usr/libexec/java_home -V |
1
2
3
4
|
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:
1
|
$ /usr/libexec/java_home -V |
1
2
3
4
5
6
|
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:
1
2
3
4
5
6
7
8
9
|
$ 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 |