My Java version is 15.0.1(default), I want to change it to java 8(1.8.0_281).
I downloaded java8, and tried several things but the version doesn't change..
change name of /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Info.plist to Info.plist.disabled
change version in ~/.bash_profile and run source ~/.bash_profile
write export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) in terminal
I restarted terminal, and run java -version..
but there is still openjdk version "15.0.1"
when I write like this, /usr/libexec/java_home -V there is no 15.0.1.
It return 1.8.0_281 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
In ~/.zshrc, there is no version infomation. just
export PATH="/usr/local/opt/openjdk/bin:$PATH" export PATH="/usr/local/opt/openjdk/bin:$PATH"
echo $JAVA_HOME show me /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
How to change java version?? help me plz (macOs is big sur, 11.2)
In mac it's pretty simple you can have two or many java versions and based on your requirement you can change that.
I found a very useful tool called jenv.
If you have already had homebrew (a package installer in mac), you can skip this step.
For installing or updating homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Installing JEnv - java version manager a cool tool helps you to switch between multiple java env on your mac
brew install jenv
Adding jEnv to your path depends on the shell you are using ~/.bash_profile or ~/.bashrc , for zsh it's ~/.zshrc. Add these two lines in your bash profile file
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
Restart the terminal or use source ~/.zshrc
Check if your JEnv is correctly installed
jenv doctor
you will get the output something like [OK] Jenv is correctly loaded
for installing java 8
  brew install --cask AdoptOpenJDK/openjdk/adoptopenjdk8
for installing java 11
brew install --cask AdoptOpenJDK/openjdk/adoptopenjdk11
for list down all the java on your machine
/usr/libexec/java_home -V
Now add these paths to jENV
Syntax: 
jenv add <your_jdk_path>
Example:
jenv add /Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home
All done. Check your version
jenv versions
For setting system wide java version
 jenv global 14.0
For setting locally to terminal
 jenv local 11
if you are using maven or gradle for your project
  # ensure that JAVA_HOME is correct
  jenv enable-plugin 
  export# make Maven aware of the Java version in use 
  (and switch when your project does)
  jenv enable-plugin maven
A reference guide https://www.jenv.be/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With