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

Publicado el: 02 enero 2024
en el 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




------


En esta página del sitio puede ver el video en línea HOW TO SWITCH JAVA VERSION and SET JAVA_HOME PATH ON MAC OS M1 M2 de Duración hora minuto segunda en buena calidad , que subió el usuario Automation Step by Step 02 enero 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 18,233 veces y le gustó 249 a los espectadores. Disfruta viendo!