Java 9 is installed in my MacBook (OS X 10.11 El Capitan). As I needed Java 8, I\'ve installed it using Homebrew.
$ brew cask install java8
How
I use the method suggested by Maarten Mulders.
I added the following to my bash profile (the file .bash_profile
in my home directory).
alias j9="export JAVA_HOME=`/usr/libexec/java_home -v 9`; java -version"
alias j8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version"
alias j7="export JAVA_HOME=`/usr/libexec/java_home -v 1.7`; java -version"
When I want to change to a Java version, I simply execute j7
in the terminal.