Juggling Multiple Versions of Java on OS X Mountain Lion
Join the DZone community and get the full member experience.
Join For Freeprior to mountain lion, java was bundled with osx. it seems that during the upgrade, the java 6 version i had on my machine was removed, apparently due to a security issue with the java runtime. this means you're forced to install the latest version, which fixed this security problem.
so i went to /applications/utilities/ open a terminal and executed the following command:
java -version ==> "no java runtime present…"
a window prompted asking to install java.click “install” and get the
latest version.i installed it but right after i downloaded and installed
the jdk se 7 from oracle.
after installation, open the java preferences (launchapad/others ) and you will see:
now i knew i had two versions of java, but which one am i using?
$ java -version java version "1.6.0_35" java(tm) se runtime environment (build 1.6.0_35-b10-428-11m3811) java hotspot(tm) 64-bit server vm (build 20.10-b01-428, mixed mode)
so what if i want to use jdk se 7 from oracle?
then i just had to drag java se 7 in the java preferences window to the first position in the list.
this time:
$ java -version java version "1.7.0_05" java(tm) se runtime environment (build 1.7.0_05-b06) java hotspot(tm) 64-bit server vm (build 23.1-b03, mixed mode)
i said to myself, "let’s find out more out how java is installed on os x." so i dug for more.
there are some very useful commands: whereis and which and ls -l .
whereis java ==> /usr/bin/java ls -l /usr/bin/java ==> /system/library/frameworks/javavm.framework/versions/current/commands/java
when i saw this i was a little bit curious so i went to list the versions directory:
cd /system/library/frameworks/javavm.framework/versions ls ==> 1.4 1.5 1.6 a currentjdk 1.4.2 1.5.0 1.6.0 current
now why do i have this old versions of java on my machine? i asked on
ask different:
http://apple.stackexchange.com/questions/57986/multiple-java-versions-support-on-os-x-and-java-home-location
$ sw_vers productname: mac os x productversion: 10.8.1 buildversion: 12b19 $ ls -l /system/library/frameworks/javavm.framework/versions total 64 lrwxr-xr-x 1 root wheel 10 sep 16 15:55 1.4 -> currentjdk lrwxr-xr-x 1 root wheel 10 sep 16 15:55 1.4.2 -> currentjdk lrwxr-xr-x 1 root wheel 10 sep 16 15:55 1.5 -> currentjdk lrwxr-xr-x 1 root wheel 10 sep 16 15:55 1.5.0 -> currentjdk lrwxr-xr-x 1 root wheel 10 sep 16 15:55 1.6 -> currentjdk lrwxr-xr-x 1 root wheel 10 sep 16 15:55 1.6.0 -> currentjdk drwxr-xr-x 7 root wheel 238 sep 16 16:08 a lrwxr-xr-x 1 root wheel 1 sep 16 15:55 current -> a lrwxr-xr-x 1 root wheel 59 sep 16 15:55 currentjdk -> /system/library/java/javavirtualmachines/1.6.0.jdk/contents
it seems all the old versions are links to the currentjdk version, which is the apple version, except a and current which is linked to a. i read something about this on this question . for me, a acts like a temp variable. if in java preferences you set this in the first position, java 6 from apple a will have java 6 from apple. if you put on the first position java se 7 from oracle, a will point to this version. current points to a.
/java -version java version "1.6.0_35" java(tm) se runtime environment (build 1.6.0_35-b10-428-11m3811) java hotspot(tm) 64-bit server vm (build 20.10-b01-428, mixed mode)
./java -version java version "1.7.0_05" java(tm) se runtime environment (build 1.7.0_05-b06) java hotspot(tm) 64-bit server vm (build 23.1-b03, mixed mode)
this means that this current directory will point to the first java version found in the java preferences. now take a look at the following:
lrwxr-xr-x 1 root wheel 59 sep 16 15:55 currentjdk -> /system/library/java/javavirtualmachines/1.6.0.jdk/contents
this means java from apple is actually installed here: "/system/library/java/javavirtualmachines/1.6.0.jdk/"
what about java se 7? i could search the filesystem to see, but i found an easier way:
if, in java preferences, java se 7 is in the first position ==>
$ /usr/libexec/java_home /library/java/javavirtualmachines/1.7.0.jdk/contents/home
if java se 6 (system) is in the first position ==>
$ /usr/libexec/java_home /system/library/java/javavirtualmachines/1.6.0.jdk/contents/home
so java on mountain lion (osx) is more likely to be installed in one of these locations:
- /system/library/java/javavirtualmachines
- /library/java/javavirtualmachines
- ~/library/java/javavirtualmachines
what about /system/library/frameworks/javavm.framework/versions? it seems like this is linked to the so-called " java bridge ." here it seems to be the native part of the java on osx installation.
Published at DZone with permission of Cristian Chiovari, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments