With Homebrew and Jenv:
Assumption: You have a Mac and have already installed homebrew.
Install Java from the Oracle website. JDK can be installed in multiple versions. It will be installed in the following location:
Without jenv, the system will use the most recently installed java.
You can use jenv: if you want to use/manage multiple versions.
Install and set up jenv:
$ brew install jenv
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
$ source ~/.zshrc
Add the installed java to jenv:
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/14.0.2.jdk/Contents/Home
To see all the installed java:
$ jenv versions
Above command will give the list of installed java:
* 18.104.22.1681 (set by /Users/lpatel/.jenv/version)
Configure the java version which you want to use:
$ jenv global 22.214.171.1241