Legen Sie in .zshrc usw. einen Alias fest, der die Umgebungsvariablen JAVA_HOME und PATH festlegt. Legen Sie für jede installierte Java Virtual Machine (JVM) fest.
# AdoptOpenJDK 8
alias setjava8="export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home; export PATH=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin:$(echo ${PATH})"
# AdoptOpenJDK 11
alias setjava11="export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home; export PATH=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin:$(echo ${PATH})"
# AdoptOpenJDK 14
alias setjava14="export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home; export PATH=/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/bin:$(echo ${PATH})"
# Amazon Corretto 8
alias setcorretto8="export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home; export PATH=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/bin:$(echo ${PATH})"
# Zulu OpenJDK 13
alias setzulu13="export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-13.jdk/Contents/Home; export PATH=/Library/Java/JavaVirtualMachines/zulu-13.jdk/Contents/Home/bin:$(echo ${PATH})"
Sie können zwischen Java-Versionen wechseln, indem Sie den von Ihnen festgelegten Aliasnamen eingeben.
$ setjava14
Überprüfen Sie die Umgebungsvariable und die Java-Version, um festzustellen, ob sie umgeschaltet wurde.
$ echo; echo JAVA_HOME=${JAVA_HOME}; echo; echo PATH=${PATH}; echo; echo 'java -version'; java -version
JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
PATH=/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
java -version
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.2+12)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.2+12, mixed mode, sharing)
Recommended Posts