How to install Java 17 on mac

最近日子時過不好啊。內心一直在哭泣...

javac -version

javac 15.0.10


我用mac, 無意間查到java版本很舊.
都已經2023年底了,還在用java 15???



雖然openJDK已經到了21,但之前開發時有遇到很多error message,是說版本太新,所以太新也不好. 而17剛剛好.

solution: 怎麼更新呢?

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







留言

這個網誌中的熱門文章

最爛的銀行服務-玉山銀行

更改google drive預設存放目錄位置Change Google Drive Default Folder Location in Windows

SMR疊瓦式hdd致命缺陷被解決????!!!

ios app 上架時app icon要注意事項

google play 正式發布前測試報告...非常好用.

Mark App Design Apps - Terms and Privacy Policy (服務條款,隱私權政策)

關於google play console app應用程式簽署

舊有app在Android 12 閃退問題& app Splash screens

寫APP真的是好工作嗎? Firebase host與我對Kotlin的感想

Google Play badge徽章產生器