下载地址:https://jdk.java.net/archive/
安装
Ξ Contents/Home → brew install openjdk@11
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/11/manifests/11.0.15-1
Already downloaded: /Users/twx/Library/Caches/Homebrew/downloads/4c40f869070c4b174f1e32b737ce0798120d815667d2825c9d49cd8db4294472--openjdk@11-11.0.15-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/11/blobs/sha256:773983fd85afacf11590381ae697d37dbf96ca9ecaf4b208354a01c62be409b7
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:773983fd85afacf11590381ae697d37dbf96ca9ecaf4b208354a01c62be409b7?se=2022-06-27T01%3A
######################################################################## 100.0%
==> Pouring openjdk@11--11.0.15.monterey.bottle.1.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
切换版本
/usr/libexec/java_home
: This will show you where the current JDK home is
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home
/usr/libexec/java_home -V
: This lists all installed JDKs, which is shown below:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
14.0.1, x86_64: "OpenJDK 14.0.1" /Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home
1.8.0_261, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home
To switch between JDKs, use /usr/libexec/java_home -v version
$ /usr/libexec/java_home -v 1.8.0_261
/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
切换:
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk11="export JAVA_HOME=$JAVA_11_HOME"
alias jdk12="export JAVA_HOME=$JAVA_12_HOME"
alias jdk14="export JAVA_HOME=$JAVA_14_HOME"
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8.0_261)
export JAVA_11_HOME=$(/usr/libexec/java_home -v 11.0.9)
export JAVA_12_HOME=$(/usr/libexec/java_home -v 12.0.2)
export JAVA_14_HOME=$(/usr/libexec/java_home -v 14.0.1)
#export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
#export JAVA_HOME=$JAVA_8_HOME
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$PATH
# default to Java 15
java15