Okay actually I want to do this kind of stuff only using .bash_profile, switching path location between JDK version. But it’s kinda odd using that manual way, so I tried to find another method to do the switching more easily. Googling and finding out that I can use Brew and Jenv to do the switching JDK version.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$brew install jenv
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
jenv add /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
You will see a list of JDK version. Switching JDK version using pattern jenv global <available JDK when you run jenv versions>
jenv global 1.8