I just installed JDK 1.8 and had a problem configuring and switching versions.
- I could not figure out where
- I wanted an easy way to switch between versions
The Manual Way
After a bit of Google searching I learned about:
- Finding/Setting JDK/$JAVA_HOME on Mac OS X
- displays the current Java version in use
- displays all current Java versions available
- displays the path for the specific version
And in the above article, I found a comment describing aliases.
I added the following aliases into my .profile
alias java6="export JAVA_HOME=`/usr/libexec/java_home -v1.6`" alias java7="export JAVA_HOME=`/usr/libexec/java_home -v1.7`" alias java8="export JAVA_HOME=`/usr/libexec/java_home -v1.8`"
After executing “
source .profile” the aliases became active.
And now I can easily switch between the various versions of Java.
- Do not add spaces in the alias between
java6 = "exportor your alias won’t work
Automating This With SDKMAN
All of the above can actually be automated with SDKMAN if you are on Mac or Unix.