MacOS – How to switch between the two Java versions in Mountain Lion now that Java Preferences is gone

javamacos

I have two versions of Java installed with Mountain Lion:

The update from Apple removes Java Preferences. In another question someone wonders about the removal of that utility.

My question is different:

  • how can I switch between the two versions now that Java Preferences is gone?

I previously used Apple's utility to set Java preferences with ease. Without that utility, is there an easy and fast way?

Best Answer

You may need two approaches:

  • one to switch the version for the applet plug-in alone
  • another approach to switch the version for other parts of the JRE without switching the version for the applet plug-in.

My recent use case:

  • Java 8 for apps that do not use the plug-in
  • Java 7 Update 9 for the applet plug-in.

To switch the applet plug-in but not other parts of the JRE/JDK from Java 8 to Java 7 Update 9

  1. quit web browsers and any other apps that use Java or the Java applet plug-in
  2. install JDK 8
  3. set aside the plug-in
  4. install JRE 7 Update 9 or JDK 7 Update 09.

Setting aside: suggested move

sudo mv /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin /private/var/tmp

If you plan to switch frequently, you may prefer a different temporary location.

Result

sh-3.2$ java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b58)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b02, mixed mode)
sh-3.2$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.8.2
BuildVersion:   12C60

At the same time:

Screenshot of Oracle's verification of Java version in Safari

To switch the applet plug-in but not other parts of the JRE/JDK from Java 7 Update 9 to Java 6 Update 37

Answers under:


To switch the JRE but not the applet plug-in from Java 8 to Java 7 Update 9

Install JDK 7 Update 09 then JDK 8

  • the OS and apps will default to use the greatest version.

Quit any apps that use Java. No need to quit the browser.

Set aside the jdk1.8… directory from

/Library/Java/JavaVirtualMachines

  • the OS and apps will use Java 7 Update 9.

To switch the JRE but not the applet plug-in from Java 7 Update 9 to Java 6 Update 37

Quit any apps that use Java. No need to quit the browser.

Set aside the jdk1.7… directory from

/Library/Java/JavaVirtualMachines

  • the OS and apps will use Java 6 Update 37.

Example

macbookpro08-centrim:~ gjp22$ java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
macbookpro08-centrim:~ gjp22$ sudo mv /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk /private/var/tmp
Password:
macbookpro08-centrim:~ gjp22$ java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

Generally

For users of OS X, some of what's provided by Oracle is initially misleading:

… and so on.

Simplicity

Whilst none of the above is as simple as switching with the Java Preferences app previously installed by Apple, the relatively simple approach of setting aside (no need for special uninstallation) is reminiscent of the wish for drag-and-drop installation … previously expressed in the openjdk-osx-build area.

Someone might like to build an app, but I should not recommend using symlinks – it would work, but could be inconsistent with future drag-and-drop approaches to installation.

Side notes

At the time of writing, the most recent supported releases for which Oracle makes updates publicly available are (for platforms other than OS X) Java 6 Update 37 and (for platforms including OS X) Java 7 Update 9.

As greater releases will be made available, please reinterpret this answer accordingly.

Java version terminology in this answer is in line with Java Help Center terminology.