Core Java

Multiple versions of Java on OS X Mountain Lion

Before Mountain Lion, Java was bundled inside OS X. It seems that during the upgrade, the Java 6 version I had on my machine was removed.
Apparently the reason for uninstalling Java during the upgrade process was caused by a security issue that the Java runtime had.In this way you are 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 I am using it ?

$ 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 had just 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 ? So 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 the 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)

So it means that in this Current directory will point to the first Java Version found in the Java Preferences.
A very interesting thing is the following information

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 on the first position is Java SE 7 ==>

$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

If in Java Preferences on the first position is Java SE 6 (System) ==>

$ /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 this locations :

  • /System/Library/Java/JavaVirtualMachines
  • /Library/Java/JavaVirtualMachines
  • ~/Library/Java/JavaVirtualMachines

What about /System/Library/Frameworks/JavaVM.framework/Versions ?
It seems that is linked to the so called “Java bridge“.Here it seems is the native part of the Java on OSX installation.

Reference: Multiple versions of Java on OS X Mountain Lion from our JCG partner Cristian Chiovari at the Java Code Samples blog.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button