Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set mac jdk version to 1.8

I have searched several ways to change JDK version on mac.

$/usr/libexec/java_home

And I got

/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

I tried

$export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

also tried

/usr/libexec/java_home 1.8.0_31 --exec javac -version

then I run

$echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

then I re-check java -version

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

How I can really change java -version on my mac.

like image 694
Michael Gao Avatar asked Feb 28 '15 07:02

Michael Gao


People also ask

Is JDK 8 and 1.8 the same?

8 and java 8?? http://www.oracle.com/technetwork/java/javase/jdk8-naming-2157130.html Java SE Development Kit 8, also known as JDK 8, has the version number 1.8. In short – 8 is product version number and 1.8 is the developer version number (or internal version number). The product is the same, JDK 8, anyways.


2 Answers

To set Java to 1.8 for your shell environment, put this in your ~/.bash_profile:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
like image 92
andrus_a Avatar answered Sep 28 '22 23:09

andrus_a


Solution without 3rd party tools:

leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default. To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command. System launcher will use the JDK with highest version among those that have an Info.plist file.

When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).

like image 32
Dev Avatar answered Sep 29 '22 00:09

Dev