$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)
$ brew install openjdk@17
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/17/manifests/17.0.4
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/17/blobs/sha256:70e3d914c8a21ce7c648751a7d32666ac03effc38786d77b62847b6fbbaa6c63
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:70e3d914c8a21ce7c648751a7d32666ac03effc38786d77b62847b6fbbaa6c63?se=2022-07-24T07%3A00%3A00Z&sig=8fFb7ytZ7eC6%2B9rv7
######################################################################## 100.0%
==> Pouring openjdk@17--17.0.4.arm64_monterey.bottle.tar.gz
==> Caveats
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"
==> Summary
🍺 /opt/homebrew/Cellar/openjdk@17/17.0.4: 640 files, 306.6MB
==> Running `brew cleanup openjdk@17`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
2. jdk 버전 변경
# 링크 추가
$ sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
# .zshrc에 추가
echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
# 확인 및 코멘트 추가
$ vi ~/.zshrc
### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
export PATH="/Users/djkang/.rd/bin:$PATH"
### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)
# openjdk17
export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
# zshrc 변경사항 적용
$ source ~/.zshrc
3. jdk 변경 확인
# 위치 확인
$ which java
/opt/homebrew/opt/openjdk@17/bin/java
# 버전 확인
$ java -version
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment Homebrew (build 17.0.4+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.4+0, mixed mode, sharing)