Contents

How to Easily Manage Your Java Development Kits with SDKMAN on Your Mac

If you’re a developer working on a Mac, you might be using multiple versions of the Java Development Kit (JDK) for different projects. Managing all these different JDK installations can be a hassle, especially if you need to switch between them frequently. Recently I showed you Jenv, that can help you with this problem, but let’s see on the another solution – SDKMAN.

In this article, I’ll show you how to easily manage your JDK installations with SDKMAN on your Mac. I’ll cover the installation process and basic usage of SDKMAN, including how to list available Java versions, install new versions, and switch between them.

Installing SDKMAN on Your Mac

The first step is to install SDKMAN on your Mac. Open your terminal app and run the following command:

$ curl -s "https://get.sdkman.io" | bash

This will download and run a script that will install SDKMAN on your machine. Once the installation is complete, close and reopen your terminal app or run the following command to reload your terminal configuration:

$ source "$HOME/.sdkman/bin/sdkman-init.sh"

This will load the SDKMAN environment variables into your terminal session. To verify that SDKMAN was installed correctly, run the following command:

$ sdk version

This command should output the current version of SDKMAN.

Listing Available Java Versions

Now that SDKMAN is installed, you can use the sdk command to manage your JDK installations. To list all available Java versions that can be installed and managed with SDKMAN, run the following command:

$ sdk list java

This will display a list of available Java versions, along with their version numbers, release dates, and vendor information. The output may look something like this:

================================================================================
Available Java Versions
================================================================================
     17.0.2-open             11.0.12-zulu              8.0.312-zulu
     16.0.2-zulu             11.0.12-amzn              8.0.292-zulu
     15.0.4-zulu             11.0.12-open              7.0.282-zulu
     14.0.2-open             11.0.12-j9                6.0.119-zulu
     13.0.6-zulu             11.0.12-tem               1.0.0-rc-16-graal
     12.0.2-open             11.0.12-oracle            1.0.0-rc-15-graal
    11.0.12-zulu             11.0.12-librca            1.0.0-rc-14-graal
    11.0.12-amzn             11.0.12-jdkhs             1.0.0-rc-13-graal
    11.0.12-open             11.0.12-jdkup             1.0.0-rc-12-graal
    11.0.12-j9               11.0.12-grl              * 1.0.0-rc-11-graal
    11.0.12-tem              11.0.12-adoptopenj9
    11.0.12-oracle           11.0.12-azul

The currently selected Java version is marked with an asterisk (*).

Installing a Java Version

To install a specific Java version, run the following command:

$ sdk install java <version>

Replace <version> with the version number of the Java version you want to install, for example:

$ sdk install java 11.0.12-zulu

This will download and install the specified Java version.

Switching Between Java Versions

Once you have installed multiple Java versions with SDKMAN, you can easily switch between them using the sdk use java command. To switch to a specific Java version, run the following command:

$ sdk use java <version>

For example, to switch to Java 11.0.12-zulu, run the following command:

$ sdk use java 11.0.12-zulu

This will set the selected Java version as the default for your terminal session. You can verify that the correct Java version is being used by running the java -version command.

Conclusion

In this article, I showed you how to easily manage your Java Development Kits with SDKMAN on your Mac. SDKMAN makes it easy to install and manage multiple JDK versions, and switch between them as needed. With these simple commands, you can make your development workflow more efficient and productive.

So, if you’re a Mac user and you work with multiple JDK versions, give SDKMAN a try. It’s a great tool that can save you time and simplify your development process.