Рет қаралды 11,674
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
------