TransWikia.com

How can I switch between the two Java versions in Mountain Lion now that Java Preferences is gone?

Ask Different Asked by Maverik on February 5, 2021

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?

5 Answers

based on user2343996's answer

alias java8="export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) && java -version"
alias java6="export JAVA_HOME=$(/usr/libexec/java_home -v 1.6) && java -version"

Answered by existeundelta on February 5, 2021

Open up a terminal use this command:

/usr/libexec/java_home -v 1.6 

You can change the 1.6 to any version of java you want to use and the command will output the location of where that version of java resides. (i.e: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home)

then you can set the JAVA_HOME like you normally would with the output of the previous command. i.e.:

export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

So to simplify; something like this should work:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)

remember to check the version with:

java -version

Hope it helps.

Answered by user2343996 on February 5, 2021

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.

Answered by Graham Perrin on February 5, 2021

It looks like you'll have to do it manually. Oracle's documentation states that only one JRE can be installed at a time.

This Apple support page describes how to switch between the Apple SE 6 JRE and the Oracle SE 7 JRE. Briefly, to switch from Oracle's JRE back to Apple's, start the Terminal app and type the following:

sudo mkdir -p /Library/Internet Plug-Ins/disabled

sudo mv /Library/Internet Plug-Ins/JavaAppletPlugin.plugin /Library/Internet Plug-Ins/disabled

sudo ln -sf /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin /Library/Internet Plug-Ins/JavaAppletPlugin.plugin

There are more (and better) instructions on the support page on how to switch Web Start back to JRE 6, and how to switch everything back to Oracle JRE 7 (reinstall the JRE).

Not as simple as using the Java Preferences utility, but better than nothing.

Answered by dfjacobs on February 5, 2021

Why do you need to have 2 versions of Java installed?

Apple doesnt have Java installed as a default update (from Lion onwards I believe). The best way to check for/install Java on a Mac is as follows :

  1. Open Terminal. Type "java" (without the quotes of course)
  2. If java isn't present you get the following : "No Java Runtime present, requesting install…"
  3. Java starts installing normally (this is the false executable starting the install)
  4. If you have java to check the version, in terminal type "java-version"

If you want to install a different version of java : Just goto the oracle site and download the newest/older jdk.

Answered by SashaZd on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP