user3025403
user3025403

Reputation: 1080

How to update Java to 7 on max OSX?

When I type

java -version

into my terminal, I get:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

However, I downloaded Java 7. One of the differences between Java 6 and Java 7 is that when I open System Preferences (Mac), I can see an icon to launch the Java control panel. I can see the Java control panel, which means that Java 7 has been downloaded properly. So how do I change my settings/configuration so that it uses the newest version that I downloaded?

Upvotes: 0

Views: 1834

Answers (2)

Ivan X
Ivan X

Reputation: 2195

Oracle Java 7 and Apple Java 6 are completely different and they coexist on the same machine as they inhabit totally separate locations.

Java 7, if installed, lives in:

/Library/"Internet Plug-Ins"/JavaAppletPlugin.plugin/Contents/Home

Java 6, if installed, lives in:

/System/Library/Frameworks/JavaVM.framework/Versions/A/

(And the more traditional Java 6 JDK is at: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home)

When you type java, you're running /usr/bin/java, which is a symbolic link to Java 6. In fact, if you type ls -l /usr/bin | grep -i java you will see a bunch of symbolic links for the typical JDK/JRE executables.

So if you have installed Java 7, and that's what you want to use from the command line, you can change into its directory and run its specific binaries in bin. To avoid that, you can add its bin directory to your Bash search path, so its contents are invoked instead of the Java 6 symlinks in /usr/bin. To do this, alter /etc/paths to add the bin directory before the first line:

{ echo "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin"; \
  cat /etc/paths; } | sudo tee /etc/paths > /dev/null

Then set the JAVA_HOME environment variable, so supporting software knows where to find Java 7:

{ echo -n "export JAVA_HOME=";
echo "/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"; } \
| sudo tee -a /etc/bashrc > /dev/null

Now, in any new Terminal window, when you type java -version, you'll see java version "1.7.0_51". (And if you still want to be able to run the Java 6 binaries, you can call them with /usr/bin/java, /usr/bin/javac, etc.)

Upvotes: 1

ihsan
ihsan

Reputation: 586

You could try issuing the following command:

update-alternatives –config java

That command will make you able to choose between Java versions. This command worked for me on a Linux-based machine, so I think there would be no different than a Mac, but I'm not sure, you could try it out.

Upvotes: 1

Related Questions