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.
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.
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`
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With