出自 http://blog.csdn.net/collonn/article/details/28483109:
Mac OS 10.9会安装jdk1.6。
苹果提供的Java都安装在/System/Library/Frameworks/JavaVM.framework/目录下,我们看一下这个目录下到底有些什么东西。
我们先看看java在哪,运行以下命令
>>whereis java
/usr/bin/java
>>ls -l /usr/bin/java
lrwxr-xr-x 1 root wheel 74 5 20 23:08 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
看到了吧,这是一个软连接,/usr/bin/java实际指向的真正可招待的文件是后面的那个java文件,好吧,我们再看看这个java文件所在目录下有什么
>>ls -l /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/
drwxr-xr-x 45 root wheel 1530 5 20 23:08 .
drwxr-xr-x 7 root wheel 238 5 20 23:08 ..
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 appletviewer
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 apt
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 extcheck
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 idlj
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jar
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 jarsigner
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 java
-rwxr-xr-x 1 root wheel 68224 5 20 23:08 java_home
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 javac
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 javadoc
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 javah
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 javap
-rwxr-xr-x 1 root wheel 49584 5 20 23:08 javaws
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jcmd
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 jconsole
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jdb
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jhat
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jinfo
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jmap
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jmc
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jps
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 jrunscript
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 jsadebugd
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jstack
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jstat
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 jstatd
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 jvisualvm
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 keytool
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 native2ascii
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 orbd
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 pack200
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 policytool
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 rmic
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 rmid
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 rmiregistry
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 schemagen
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 serialver
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 servertool
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 tnameserv
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 unpack200
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 wsgen
-rwxr-xr-x 1 root wheel 54640 5 20 23:08 wsimport
-rwxr-xr-x 1 root wheel 54624 5 20 23:08 xjc
这个目录怎么这个熟悉,原来这个目录就是我们通常所说的JAVA_HOME/bin/
好,我们再回过头来,看一看别外一个目录。
>>cd /System/Library/Frameworks/JavaVM.framework
>>ls -l
drwxr-xr-x 11 root wheel 374 5 20 23:08 .
drwxr-xr-x 118 root wheel 4012 2 18 13:50 ..
lrwxr-xr-x 1 root wheel 27 5 20 23:08 Classes -> Versions/CurrentJDK/Classes
lrwxr-xr-x 1 root wheel 28 5 20 23:08 Commands -> Versions/CurrentJDK/Commands
lrwxr-xr-x 1 root wheel 27 5 20 23:08 Frameworks -> Versions/Current/Frameworks
lrwxr-xr-x 1 root wheel 24 5 20 23:08 Home -> Versions/CurrentJDK/Home
lrwxr-xr-x 1 root wheel 23 5 20 23:08 JavaVM -> Versions/Current/JavaVM
lrwxr-xr-x 1 root wheel 29 5 20 23:08 Libraries -> Versions/CurrentJDK/Libraries
lrwxr-xr-x 1 root wheel 26 5 20 23:08 Resources -> Versions/Current/Resources
drwxr-xr-x 11 root wheel 374 5 20 23:08 Versions
-rw-r--r-- 1 root wheel 104 2 18 13:48 module.map
看到了吧,几乎所有的软连接都指向了该目录的Versions目录下的子目录,好,我们进入到Versions目录中,看看这个目录里有什么东西。
>>cd Versions/
>>ls -l
drwxr-xr-x 11 root wheel 374 5 20 23:08 .
drwxr-xr-x 11 root wheel 374 5 20 23:08 ..
lrwxr-xr-x 1 root wheel 10 5 20 23:08 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 5 20 23:08 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 5 20 23:08 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 5 20 23:08 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 5 20 23:08 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 5 20 23:08 1.6.0 -> CurrentJDK
drwxr-xr-x 7 root wheel 238 5 20 23:08 A
lrwxr-xr-x 1 root wheel 1 5 20 23:08 Current -> A
lrwxr-xr-x 1 root wheel 59 5 20 23:08 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
看至了吧,所有有java版本都指向了同一个目录CurrentJDK,而CurrentJDK指向了另外一个目录,好,我们看看这个目录里有什么东西
>>cd /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
>>ls -l
drwxr-xr-x 10 root wheel 340 10 11 2013 .
drwxr-xr-x 3 root wheel 102 10 11 2013 ..
drwxr-xr-x 12 root wheel 408 5 20 23:08 Classes
drwxr-xr-x 41 root wheel 1394 5 20 23:08 Commands
drwxr-xr-x 6 root wheel 204 5 20 23:08 Home
-rw-r--r-- 1 root wheel 1961 5 20 23:08 Info.plist
drwxr-xr-x 50 root wheel 1700 5 20 23:08 Libraries
drwxr-xr-x 3 root wheel 102 5 20 23:08 MacOS
drwxr-xr-x 32 root wheel 1088 5 20 23:08 Resources
-rw-r--r-- 1 root wheel 462 5 20 23:08 version.plist
看到Home目录了吧,这个目录就是我们平时所说的JAVA_HOME了。
--其次,从Oracle官方下载个jdk1.7_xx.dmg,按照提示安装就可以了。
oracle提供的Java都安装在/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk目录下。
--vim ~/.bash_profile,添加如下代码。
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH