最新バージョンのJDKをmacにインストールする流れでハマったので忘れないようにメモ
環境
Mac Os catalina 10.15.7
概要
※調べるとcaskを使う記事が複数でてきましたが使わなくてよかったので以下で実施
% brew install java
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/15.0.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:fca110fb6caad1228156b587a3ca9fa9ab5a
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:fca110fb6caad1228156b
######################################################################## 100.0%
==> Pouring openjdk--15.0.2.catalina.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
==> Summary
🍺 /usr/local/Cellar/openjdk/15.0.2: 614 files, 324.9MB
よく見ると上記の文章内に全部記載されているんですが、、、
インストールされたか確認してみると以下
% java --version
No Java runtime present, requesting install.
どないなっとんねんと思いましたが、シンボリックリンクを貼って解消(インストール時のログにも出てますね)
% sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
再度確認すると問題なくjavaのバージョンが確認できました。
% java --version
openjdk 15.0.2 2021-01-19
OpenJDK Runtime Environment (build 15.0.2+7)
OpenJDK 64-Bit Server VM (build 15.0.2+7, mixed mode, sharing)