Set JAVA_HOME on Mac

759 Views Asked by At

I´ve tried everything but can´t set JAVA_HOME on a mac. Some say´s all you got to do is echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile

I did, and restarted my shell and this is what it shows up:

-bash: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home: is a directory

This ALWAYS shows up no matter which method of setting the variable I´ve used. My jdk 7 that I want to use is in my Library but the 1.6 that´s being used now is in System folder.

1

There are 1 best solutions below

2
On BEST ANSWER

I have two versions of Java installed - 1.6 and 1.7 on my mac. Depend upon which version I would like to use, I just change the entry in .bash_profile file.

Below is my .bash_profile looks like for version 1.6

cat .bash_profile

export JAVA_HOME='$(/usr/libexec/java_home -v 1.6)'