I’ll introduce how to install and manage multiple versions of Java using the asdf plugin asdf-java.
I needed to install Java on M1 macOS and had plans to continue development while switching between multiple Java versions, so I decided to use asdf-java.
First, complete the asdf installation [M1 macOS edition].
As a prerequisite, I’ll install the latest versions of corretto-17
and corretto-18
respectively.
asdf plugin-add java https://github.com/halcyon/asdf-java.git
asdf list-all java
asdf install java corretto-17.0.4.9.1
asdf install java corretto-18.0.2.9.1
asdf list java
corretto-17.0.4.9.1
corretto-18.0.2.9.1
asdf current
java ______ No version is set. Run "asdf java "
asdf global java corretto-18.0.2.9.1
asdf current
java corretto-18.0.2.9.1 /Users/your_name/.tool-versions
cat ~/.tool-versions
java corretto-18.0.2.9.1
asdf local java corretto-17.0.4.9.1
asdf current
java corretto-17.0.4.9.1 /Users/your_name/sample/.tool-versions
cat .tool-versions
java corretto-17.0.4.9.1
Add the following to .zshrc
:
. ~/.asdf/plugins/java/set-java-home.zsh
That’s all from the Gemba, where I started managing multiple Java versions with asdf.