Mac に Homebrew で OpenJDK11 を インストール する

http://openjdk.java.net/


➜  ~ brew search openjdk
==> Formulae
openjdk         openjdk@11     openjdk@8       openj9          openvdb

...

openjdk@11 — Homebrew Formulae
👉 openjdk@11 — Homebrew Formulae 


➜  ~ brew info openjdk@11
openjdk@11: stable 11.0.12 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk@11.rb
License: GPL-2.0-only
==> Dependencies
Build: autoconf ✔
==> 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"

...


➜  ~ brew install openjdk@11
...

「keg-only」は「リンクされていない」。


➜  ~ sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
➜  ~ echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
➜  ~ export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"


➜  ~ vi .zshrc                                                                      
...
#export PATH="/usr/local/opt/openjdk@11/bin:$PATH"

JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
JAVA_11_HOME=$(/usr/libexec/java_home -v11)

export JAVA_HOME=$JAVA_11_HOME
export PATH="$JAVA_HOME/bin:$PATH"


➜  ~ source ~/.zshrc


➜  ~ ls -l /Library/Java/JavaVirtualMachines
total 0
drwxr-xr-x  3 root  wheel  96 11 10  2020 adoptopenjdk-8.jdk
lrwxr-xr-x  1 root  wheel  45 11 30 09:43 openjdk-11.jdk -> /usr/local/opt/openjdk@11/libexec/openjdk.jdk


➜  ~ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    11.0.12 (x86_64) "Homebrew" - "OpenJDK 11.0.12" /usr/local/Cellar/openjdk@11/11.0.12/libexec/openjdk.jdk/Contents/Home
    1.8.0_275 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/usr/local/Cellar/openjdk@11/11.0.12/libexec/openjdk.jdk/Contents/Home


➜  ~ java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Homebrew (build 11.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)


➜  ~ javac -version
javac 11.0.12


👉 OpenJDK 
👉 AdoptOpenJDK - Open source, prebuilt OpenJDK binaries 
👉 Adoptium - Open source, prebuilt OpenJDK binaries 

👉 KMM まとめ 速報 - Kotlin Multiplatform Mobile 【#ios | #android】 

👉 MacでインストールされているJavaを確認する方法 - Qiita 
👉 Homebrewでjavaをインストールする方法 - Qiita 
👉 MacにJava開発環境をインストールする - Qiita 


関連ワード:  Androidapple今さら聞けない開発