Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am trying to run a server that requires Java 7 using terminal. After installing Java 7, typing java -version in terminal still shows Java 6. Previously, I would use the Java Preferences application, but Apple has removed it. Does anyone have any idea how to change the Java version the system uses without the Java Preferences application? Or if anyone knows a download link for Java Preferences, that would be greatly appreciated as I am able to achieve the same results by just using that. Thank you so much!

I am using the latest version of Mac OS X

share|improve this question

migrated from stackoverflow.com Dec 24 '12 at 8:26

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Journeyman Geek Feb 3 at 1:44

This question was marked as an exact duplicate of an existing question.

    
Type which java and see where it's loading Java from. Maybe you installed a separate copy somewhere and that's in your path. – Marvo Dec 24 '12 at 0:59
    
Um, with Java Preferences you mean the Java Control Panel window you could once call from either Utilites or System Preferences? With 1.7 it's in System Preferences.. – dbf Dec 24 '12 at 1:17
    
Spotlight :) command-space then type java preferences, it has not been removed. – Brian Roach Dec 24 '12 at 1:30

http://www.adam-bien.com/roller/abien/entry/java_se_development_kit_7

export JAVA_HOME="/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home"

Try entering that line in terminal. You can also type- java -version to see which version is currently running.

I've had to do the exact opposite as you, revert to Java 1.6 after having 1.7 installed.

This is old but provides some background that may help lead you on the right path: https://blogs.oracle.com/bobby/entry/switching_jdks_on_mac

Just beware that this situation can be a bit of a head ache to solve...!

share|improve this answer
    
Alternatively to exporting JAVA_HOME, one may run sudo echo "/Library/Java/... path ..." > /etc/paths.d/jdk1.7.0_09 – ignis Dec 24 '12 at 1:27
    
In my case, the path ends with /bin (i.e. /Library/Java/JavaVirtualMachines/jdk1.7.0.jdk/Contents/Home/bin) – ignis Dec 24 '12 at 1:28

You can have multiple versions of Java JDK installed at the same time. You can, then, set the version of the JDK to use within terminal. You can also set the version you want as the default in, ~/.bash_profile

export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`
export JAVA_HOME=`/usr/libexec/java_home -v '1.7*'`
export JAVA_HOME=`/usr/libexec/java_home -v '1.8*'`
share|improve this answer