adam bien's blog

How to Quickly Switch Between JDKs Without Tools 📎

You can quickly switch between JDKs with two aliases (tested on MacOS):

alias j8='export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home;javaPATH' alias javaPATH='export PATH=$JAVA_HOME/bin:$PATH'

You can switch to Java 8 by running j8 in your terminal. (Quickly switching to Java 8 is especially useful for code archealogists and historians.)