0

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?

4
  • Are you trying to do this on a mac? If yes, have you tried this -java.com/en/download/help/mac_java_update.xml? Commented Jun 6, 2014 at 19:41
  • do mac have environment variables? Commented Jun 6, 2014 at 19:41
  • I think this should help you: Clicky! Commented Jun 6, 2014 at 19:43
  • @BheshGurung : Yes, I'm using a mac. I have done that and it says I already have the recommended Java version. Commented Jun 6, 2014 at 19:57

2 Answers 2

1

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.)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

@user3025403, then the only way to change the Java version is by setting/changing the Java environment variables. If you google it up, you will find enough questions and answers about it. Good luck!
update-alternatives is specific to the Debian package management system. OS X doesn't have any kind of included package management system at all, so this won't work; and none of the third-party ones that exist (Homebrew, MacPorts, Fink) use this mechanism.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.