MacOS – Multiple Java versions support on OS X and JAVA_HOME location

javamacos

I know is possible to have multiple versions of Java on OS X but i find it difficult to understand how it works.

I upgraded to Mountain Lion and now echo $JAVA_HOME is empty.

However in /System/Library/Frameworks/JavaVM.framework/Versions/

1.4     1.5     1.6     A       CurrentJDK
1.4.2   1.5.0   1.6.0   Current

When I go into 1.4.2 and I execute java - version or ./java -version

Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)

So why all those versions are used for if they have same version of Java?

Then I downloaded the JDK 7 from Oracle and installed it.

Where a new JDK is usually installed?

And final question : How can I choose which version should run by default by all applications?

In Win. I set JAVA_HOME to the C:/ProgramFiles/Java/.…
I put in Path : location to JAVA_HOME/bin and that's it.

Best Answer

Contents of /System/Library/Frameworks/JavaVM.framework/Versions

For most use cases, CurrentJDK should provide the functionality of current and past versions of the JDK.

Not all past versions, but the versions most commonly required:

sh-3.2$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.8
BuildVersion:   12A269
sh-3.2$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions
total 64
lrwxr-xr-x  1 root  wheel   10 17 Jul 07:47 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 17 Jul 07:47 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 17 Jul 07:47 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 17 Jul 07:47 1.5.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 17 Jul 07:47 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 17 Jul 07:47 1.6.0 -> CurrentJDK
drwxr-xr-x  8 root  wheel  272 17 Jul 07:48 A
lrwxr-xr-x  1 root  wheel    1 17 Jul 07:47 Current -> A
lrwxr-xr-x  1 root  wheel   59 17 Jul 07:47 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
sh-3.2$