How to install Java 17 on mac
最近日子時過不好啊。內心一直在哭泣...
javac -version
javac 15.0.10
都已經2023年底了,還在用java 15???
macOS - How to install Java 17
brew install openjdk@17
然後他就回應:
openjdk@17 is already installed but outdated (so it will be upgraded).
???
然後回覆:
==> Caveats
==> openjdk@17
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
openjdk@17 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have openjdk@17 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk@17 you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"
安裝完不代表沒事,
要手動執行 sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
javac --version
javac 17.0.9
重開機在測試一次,出現下面這幾行字這樣才算成功.
openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment Homebrew (build 17.0.9+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.9+0, mixed mode, sharing)
番外篇: >>> 查詢mac目前有安裝的java 版本:/usr/libexec/java_home -V
Matching Java Virtual Machines (3):
17.0.9 (arm64) "Homebrew" - "OpenJDK 17.0.9" /opt/homebrew/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
15.0.10 (arm64) "Azul Systems, Inc." - "Zulu 15.46.17" /Users/markchiu/Library/Java/JavaVirtualMachines/azul-15.0.10/Contents/Home
11.0.20 (arm64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/markchiu/Library/Java/JavaVirtualMachines/corretto-11.0.20/Contents/Home
/opt/homebrew/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
我的mac有安裝三種版本java : 17,15,11
看自己使用哪個版本: (mac 用$JAVA_HOME ,大小寫有差,都要大寫 )
echo $JAVA_HOME
回應:
/opt/homebrew/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
留言
張貼留言