Install Homebrew by running the following command in the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Run the following commands in the terminal to install Java8:
brew cask install java
To install other versions of Java simply add the version number:
brew cask install java6
brew cask install java7
In order to easily switch between Java versions with a short command, the bash profile will have to be updated. If you have not previously created a bash profile do so by running the following command:
Now run the next command to open the bash profile:
open -a TextEdit.app .bash_profile
Add the following lines to your bash profile and save it
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"
alias j6=“export JAVA_HOME=
/usr/libexec/java_home -v 1.6; java -version”
You can now switch between Java versions by typing j6, j7 or j8 in the terminal.
Please sign in to leave a comment.