1

I have installed Java 1.7 on my mac at

/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

In Command line I set the java version as

export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home'

Now when i do java -version

It shows the correct java version 'java 1.7'

However, when i open a new terminal and do java -version,

it again shows wrong java version 'java 1.8' // I need to use java 1.7 for certain applications

How to make sure that correct java version is shown each time i open the terminal?

3 Answers 3

1

Sounds like you have both installed (OSX Yosemite iirc installs 1.8 by default) try adding 1.7 to your java --alternatives and or use the defined path (symlinks are lovely for this)

1

Try

which java

This should tell you where the executable is. I agree with linuxdev2013, it is likely that you have multiple versions installed. I imagine that the newer version is probably in your path.

0

You can swap between installed versions of the JDK on the fly, within the terminal, using;

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*'`

(use the same command in your ~/.bash_profile to set the required default, too!)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .