7

The first time I tried to use Java on Mountain Lion, it installed automatically. Unfortunately, it installed Java 6, so I installed Java 7. If I navigate to Java in System Preferences, only Java 7 is listed. How do I switch to Java 7, or remove Java 6?

6

Apple's tools don't see Java 7, Oracle's tools don't see Java 6; it's all a bit ugly. Luckily there's an ugly fix to go with it!

Normal Mac Java 6 running on 10.8:

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)

Install the Java 7 JDK (not just the JRE) from Oracle.

Move the system java out of the way (so you can get it back if you want):

sudo mv /System/Library/Java/JavaVirtualMachines/1.6.0.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdkx

Then symlink 7 in place of 6:

sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

and voila:

java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)

I've not had trouble with any java apps so far (apart from java preferences which checks which java it's running under).

There's probably a better way of doing this, but it works for me.

  • I found that I had to open Java Preferences after doing this and drag java7 to the top of the the preferred order dialog which was presented, otherwise java6 was still used – ianbarker Sep 6 '12 at 8:24
2

To switch to Java 7 for when Java is run from the terminal, I added the following line to ~/.profile:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home
2

$ cp -r /Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk /System/Library/Java/JavaVirtualMachines/

$ sudo ln -sF /System/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk CurrentJDK

$ java -version java version "1.7.0_12-ea" Java(TM) SE Runtime Environment (build 1.7.0_12-ea-b05) Java HotSpot(TM) 64-Bit Server VM (build 24.0-b26, mixed mode)

You must log in to answer this question.

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