HOW TO SWITCH JAVA VERSION and SET JAVA_HOME PATH ON MAC OS M1 M2

Publicado em: 02 Janeiro 2024
no canal de: Automation Step by Step
18,233
249

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




------


Nesta página do site você pode assistir ao vídeo on-line HOW TO SWITCH JAVA VERSION and SET JAVA_HOME PATH ON MAC OS M1 M2 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Automation Step by Step 02 Janeiro 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 18,233 vezes e gostou 249 espectadores. Boa visualização!