If you are a developer you need sometimes a diferent version of the JDK. MacOS comes also with his own JDK. So, how can you manage all the installed JDKs?
jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable.
Install it:
brew install jenv
To set it up execute the following commands at the command line:
export JENV_ROOT=/usr/local/opt/jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
Search for your JDKs. Usually they are in /Library/Java/JavaVirtualMachines/
Add all the JDKs to jenv:
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
$ jenv versions
system
oracle64-1.6.0.39
* oracle64-1.7.0.11 (set by /Users/hikage/.jenv/version)
$ jenv global oracle64-1.6.0.39
$ jenv local oracle64-1.6.0.39
$ jenv shell oracle64-1.6.0.39