1. Modify the .bash_profile file through the vi command
2. Enter the following:
# Mac default JDK 6 (Mac comes with a jdk6 version by default)
export JAVA_6_HOME=`/usr/libexec/java_home -v 1.6`
# set JDK 7
export JAVA_7_HOME=`/usr/libexec/java_home -v 1.7`
# set JDK 8
export JAVA_8_HOME=`/usr/libexec/java_home -v 1.8`
#Default JDK 6
export JAVA_HOME=$JAVA_6_HOME
#alias command to dynamically switch JDK version
alias jdk6="export JAVA_HOME=$JAVA_6_HOME"
alias jdk7="export JAVA_HOME=$JAVA_7_HOME"
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
3, then execute source .bash_profile to take effect the new configuration
When using, switch the different versions by executing jdk6, jdk7, jdk8 on the command line