STEP 1 : Open Terminal. Check java version java -version
STEP 2 : Check java compiler version javac -version
STEP 3 : Run command /usr/libexec/java_home -V This will show the available versions
STEP 4 : Goto folder - /Library/Java/JavaVirtualMachines This should have folders of all Java/JDK available on the system
STEP 5 : Goto the folder of JAVA you want and get the path of its home folder (which has bin folder)
STEP 6 : On terminal run the following commands
echo $JAVA_HOME
export JAVA_HOME=JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
echo $JAVA_HOME
To set the path permanently
echo $SHELL
Note: if you are using older mac os, for the command echo $SHELL you may get result like .bash_profile
Then your default profile is bash and the changes you will make will be in file .bash_profile and not .zshrc
So you can replace in the below commands .zshrc with .bash_profile
pwd
open .zshrc
nano .zshrc | vi .zshrc
open .zshrc
Add the following:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
export PATH="/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:$PATH"
Save and close
source .zshrc
STEP 7 : Open a new terminal and check
java -version
javac -version
echo $JAVA_HOME
------------------------------------------
how to change java version on mac m1 m2
how to switch between java versions on mac
how to set JAVA_HOME path on mac m1 m2
how to set java home path in file permanently
------
On this page of the site you can watch the video online HOW TO SWITCH JAVA VERSION and SET JAVA_HOME PATH ON MAC OS M1 M2 with a duration of hours minute second in good quality, which was uploaded by the user Automation Step by Step 02 January 2024, share the link with friends and acquaintances, this video has already been watched 18,233 times on youtube and it was liked by 249 viewers. Enjoy your viewing!