Ask Different is a question and answer site for power users of Apple hardware and software. 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

I am using a MackBook Pro with Mac OS X 10.8.2. I currently have Java 6 installed:

wdb-laptop:~ wdb$ java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

I would like to install Java 7 to play with JavaFX, however, all of my apps for work are still on Java 6. So I would like to install Java 7 "on the side". Is his possible? If so, how? I want to make sure I will not loose my Java 6 installation if I run the .dmg from Oracle.

share|improve this question
up vote 6 down vote accepted

The oracle Java 7 does not remove the Apple supplied Java 6. It does however change /usr/bin/java to start the Oracle Java.

To start a jar with Java 6 instead of just using java on the command line put in the full path to the java i.e. /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java

share|improve this answer

I had a similar situation at work, so I did a bit of research and, with a couple minutes of setup, it can be almost painless to switch back and forth between Java 6 and 7 (or 7 and 8, for that matter - this method is version agnostic).

For anyone with java installed, /usr/libexec/java_home will show the JAVA_HOME directory, but it's especially powerful when you have multiple versions of java installed side-by-side on OS X.

Using the -V flag, you can see all of the installed JVMs:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.7.0_67, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
    1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-466.1, i386:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

You can also get the JAVA_HOME value for a specific JVM like this:

$ /usr/libexec/java_home -v 1.6
$ /usr/libexec/java_home -v 1.7

Putting this all together, this is what I added to my ~/.profile:

## java home
alias j6="export JAVA_HOME=\$(/usr/libexec/java_home -v 1.6);echo 'using Java 6'"
alias j7="export JAVA_HOME=\$(/usr/libexec/java_home -v 1.7);echo 'using Java 7'"
## manual switch for 1.6 or 1.7
j6 ## enable java 6 (or just run j6 in terminal)
## j7 ## enable java 7 (or just run j7 in terminal)

So you can see that right now, my terminal defaults to Java6, but I can switch this by just typing j7 on the command line (or editing the ~/.profile):

$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)    
$ j7
using Java 7
$ java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.