Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Maybe of interest since Oracle recently uses the term JRE to describe the Java applet plug-in alone (confusing!); and since users of OS X can now use two different versions concurrently (one version for the plug-in, a different version for apps that do not use the plug-in): How to best manage different java versions on Mountain Lion? – Graham Perrin Nov 3 '12 at 18:43
up vote 3 down vote accepted

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
share|improve this answer

Paths used for installation of JDKs


ls -l /Library/Java/JavaVirtualMachines

Other paths may be used but for the current JDK from Oracle, installed to Mountain Lion, you'll probably find the .jdk bundle at that path.

share|improve this answer

Preferring a version of Java

Use Java Preferences in the normal way.

Depending on what you have installed in addition to Apple's distribution of Java, the first tab of the utility may appear a little different.

An example, without the familiar options for applets and Java Web Start:

Screenshot of Java Preferences

There is some background reading on how this works at the command line level. The command line tool java_home reports back this preference setting.

$ /usr/libexec/java_home

The /usr/bin/java placeholder app makes use of these settings run the preferred version of Java.

$ which java

$ java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)

Finally when configuring JAVA_HOME in a launch script for Tomcat or Maven you can hook into the preference system:

export JAVA_HOME=`/usr/libexec/java_home`

Answers elsewhere note that Java may be installed at several paths – 

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

– but for what's currently described in the question here, the JDK from Oracle on Mountain Lion, only one path is likely.

share|improve this answer
Thanks for the community edit, should there be a different link for the background reading? – Graham Perrin Jul 31 '12 at 5:34
Java Preferences is no longer supported and is actually removed when one applies the Java 2012-006 update. This is part of Apple's move away from providing and supporting Java. – BryanH Jan 18 '13 at 22:39
@BryanH thanks – this answer was given some months before Java for OS X 2012-006 – see the linked question. Also please note that whilst Apple moves away from distributions of the JRE, we should not assume that Apple will cease to support Java. – Graham Perrin Jan 19 '13 at 6:55
Yes, thanks. I guess I should clarify that "support" means that Apple is no longer providing or answering technical questions about the Java Virtual Machine for OSX. It is up to Oracle (or another third party) to write and maintain said JVM. – BryanH Jan 21 '13 at 20:14

Since Mac OS X 10.8.2 Build 12C60 Java Preferences doesn't show anymore the older versions.

share|improve this answer

protected by Community Jun 8 '13 at 11:58

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.