Cambiar rápidamente de versión Java en macOS

Switching between Java versions on Mac OS Big Sur
I upgraded my Mac OS to Big Sur earlier this week. The default java home has been java 8 for quite some time. However, I want to now start using java 12 for new projects, and then switch back to java 8 for maintenance of old projects.
I had two aliases that have been working well, but now all of a Sunday, they don’t give the desired result.
alias j8=’/usr/libexec/java_home -V 1.8.0;export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0);java -version;’
alias j12=’/usr/libexec/java_home -V 12.0.1;export JAVA_HOME=$(/usr/libexec/java_home -v 12.0.1);java -version’
After much research and googling, and hair pulling I was able to finally find an answer:
alias j8=’unset JAVA_HOME;/usr/libexec/java_home -V “1.8.0”;export JAVA_HOME=$(/usr/libexec/java_home -v “1.8.0”);java -version;’
alias j12=’unset JAVA_HOME;/usr/libexec/java_home -V “12.0.1”;export JAVA_HOME=$(/usr/libexec/java_home -v “12.0.1”);java -version’
Unsetting JAVA_HOME is the first thing one needs to do, and then also making sure that the version is in quotes. All seems to be well now and I am able to nicely switch between the two versions.

https://nguni52.medium.com/switching-between-java-version-on-mac-os-big-sur-8e1998345951


Tu opinión es importante para mi, ¿Te ha resultado útil este artículo?

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

*