Managing Multiple Java Versions with asdf

Tadashi Shigeoka ·  Tue, August 30, 2022

I’ll introduce how to install and manage multiple versions of Java using the asdf plugin asdf-java.

asdf-java

Background: Java Version Management with asdf

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.

Prerequisites: Installing asdf

First, complete the asdf installation [M1 macOS edition].

Assumption: Using Java corretto

As a prerequisite, I’ll install the latest versions of corretto-17 and corretto-18 respectively.

Installing the asdf-java Plugin

asdf plugin-add java https://github.com/halcyon/asdf-java.git

List of Java Versions Available for Installation with asdf-java

asdf list-all java

Installing Java with asdf

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 "

Setting Global Environment to Use corretto-18 with asdf

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

Setting Current Directory to Use corretto-17 with asdf

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

Setting Environment Variable JAVA_HOME

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.