39

I performed a clean installation of Mountain Lion and installed JDK7.

java -version in Terminal returns java version "1.7.0_05" correctly, still Java Preferences and some other Java programs (such as Eclipse) result in prompts to install Java SE 6.

I can start Eclipse perfectly from the command line with Java 7.

Is there a way to get this working without having to install Java 6?

4
  • 1
    This is really messed up. Why on earth is this still not fixed? Isn't increased security the main motivation for why Apple gave up control over the Java update procedure? Why then does OSX still prompt me to install an outdated Java? Yikes!
    – gentmatt
    Jan 30, 2013 at 15:08
  • @gentmatt Java 7 is not a simple update for Java 6 - it is more like changing OSs. SOme things will break using the larger version and both major versions are updated for security fixes
    – mmmmmm
    Mar 25, 2013 at 17:42
  • @gentmatt Apple didn't want Java anymore and essentially abandoned it. Oracle chose to pick up the ball. Apr 15, 2013 at 10:41
  • 1
    It's still stupid to require Java 6, given that it's now deprecated… Jul 27, 2013 at 13:54

3 Answers 3

27

JDK 7 will be installed under /Library/Java/JavaVirtualMachines/1.7.0.jdk, JDK 6 under /System/Library/Java/JavaVirtualMachines.

To trick OS X to accept Java 7 instead of proposing to install Java 6 a simple symlink is enough:

sudo mkdir /System/Library/Java/JavaVirtualMachines
sudo ln -s /Library/Java/JavaVirtualMachines/1.7.0.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

Most Java Programms will run with this little hack without the need to install Java 6. OS X's Java Preferences (and maybe some others) will not as it seems to explicitly check the version of the JVM when it is started.

6
  • 1
    The second line should not have "su", it should be "sudo ln -s ....." Aug 17, 2012 at 8:15
  • 3
    I just did a fresh install including JDK 7u9, and it was installed to /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk; the instructions worked fine otherwise. Nov 22, 2012 at 1:05
  • 3
    Watch out for doing the symlink... Apple released 1.6 security update recently. If you apply this update from Apple, the symlink seems to fool the update and installs 1.6 update into where the symlink points to, i.e. Oracle's 1.7.
    – user39972
    Jan 19, 2013 at 18:04
  • This could break things if a Java program requires Java 6 and not 7 it could break when you use the other version.
    – mmmmmm
    Mar 25, 2013 at 17:43
  • Here is a better solution if you are on Mavericks: stackoverflow.com/questions/19563766/…
    – jedesah
    Jan 28, 2014 at 3:10
4

Note: if you have something that really needs java6 and won't work with java7, then you might want to hold-off on installing java7. The reason is it might be a little tricky to try to keep both 6 and 7 on same macintosh, as the 7 pkg does some messing with some of the apple-6-java items, as detailed below. So, I'll be looking for some step-by-step instructions on keeping 6 and 7 on same mac before rolling this out... See also http://reviews.cnet.com/8301-13727_7-57533880-263/java-preferences-missing-after-latest-os-x-java-update/ on Oct 18, 2012.

DETAILS The preinstall shell script in jre-7u9-macosx-x64.dmg just removes the Apple pref-pane (as well as plug-in), without warning, below.

#!/bin/bash
PLUGIN_BASEDIR=/Library/Internet\ Plug-Ins
PLUGIN_NAME=${PLUGIN_BASEDIR}/JavaAppletPlugin.plugin
MKDIR=`which mkdir`
RM=/bin/rm
# Remove the symlink before installation forcing ystem Preferences.app to refresh its cache
PREF_PANE_NAME=JavaControlPanel.prefpane
PREF_PANE_DEST=/Library/PreferencePanes/
# Actually removes the symlink
if [[ -h "${PREF_PANE_DEST}/${PREF_PANE_NAME}" ]]; then
     ${RM} -rf "${PREF_PANE_DEST}/${PREF_PANE_NAME}"
fi
# Create the /Library/Internet Plug-Ins if not present
if [[ ! -d "${PLUGIN_BASEDIR}" ]]; then
     ${MKDIR} -p "${PLUGIN_BASEDIR}"
fi
# If Apple's plugin is present, then delete it
if [[ -h "${PLUGIN_NAME}" ]] && [[ -d "${PLUGIN_NAME}" ]]; then
    ${RM} -rf "${PLUGIN_NAME}"
fi

=== And the post install script sets up a symlink ===

#!/bin/bash
LN=`which ln`
CHOWN=`which chown`
PLUGIN_FILEPATH=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
PREF_PANE_NAME=JavaControlPanel.prefpane
PREF_PANE_SRC=/Library/Internet\ Plug-       Ins/JavaAppletPlugin.plugin/Contents/Home/lib/deploy/JavaControlPanel.prefpane
PREF_PANE_DEST=/Library/PreferencePanes/
if [ ! -h "${PREF_PANE_DEST}/${PREF_PANE_NAME}" ]; then
    ${LN} -s "${PREF_PANE_SRC}" "${PREF_PANE_DEST}"
fi
${CHOWN} -R root:wheel "${PLUGIN_FILEPATH}"
-2

Mountain Lion with Java 7 alone

You're on the right track … 

Without installing Java 6

… prompts to install, as described in the question, are to be expected.

So my short answer is yes, you can have Java 7 alone; but not without an installation of Java 6.

Try:

  1. allow Apple's installation of Java
  2. remove, from the two directories below, the version(s) of Java that are no longer required:

    /Library/Java/JavaVirtualMachines

    /System/Library/Java/JavaVirtualMachines

(For a case such as this, I reckon you can safely ignore the usual advice to not interfere with /System stuff.)

2
  • 2
    Java 7 is installed under /Library/Java/JavaVirtualMachines while Java 6 is under /System/Library/Java/JavaVirtualMachines Deleting 1.6.0.jdk from /System/Library/Java/JavaVirtualMachines results in the installation dialog poping up again. What seems to work is to make a symlink 1.6.0.jdk (under /System/...) to the 1.7.0.jdk (under /Library/...). Java Programs that do not check the Java version run fine (Java Preferences blocks at start as it seems to check if Java 5 or 6 is installed)
    – Nicolas
    Jul 31, 2012 at 18:46
  • Cool – would you like to add your own answer? Please vote mine down – I won't take offence – the guess was clearly incorrect for the question, a vote down will help other users to not make similarly mistaken guesses for Java-related issues. Jul 31, 2012 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .