Use Multiple Java versions using SDKMAN

What is SDKMAN?

  • SDKMAN is a popular command-line tool for managing multiple versions of Java and other software development kits (SDKs).
  • It was created to simplify the process of installing, managing, and switching between different versions of SDKs.
  • With this tool, developers can easily manage multiple versions of Java on their development machines.
  • SDKMAN supports a wide range of SDKs, including Java, Groovy, Scala, Kotlin, and many others.
  • Also, this SDKMAN is a community-driven project that is open-source and free to use.
  • It is available for different operating systems such as Linux, macOS, and Windows.

In this article, I will explore how SDKMAN works and how it can be used to manage multiple versions of Java in Linux.

Installing SDKMAN

To use SDKMAN, you must first install it on your system.

To install SDKMAN, open a terminal window and enter the following command

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

This command downloads the SDKMAN installation script and executes it on your system.

initialize SDKMAN

Use the below command to initialize the SDKMAN on your system.

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

You can check the version with the below command.

SDK version

Once the installation is complete, you can use the SDK command to manage your SDKs.

List the available java versions

you can list the available Java versions that can be installed using SDKMAN by using the following command.

sdk list java

This command will display a list of Java versions that are available for installation, along with their respective identifiers, descriptions, and release dates.

For example, the output may look something like this

Installing Java using SDKMAN

To install a specific version of Java using SDKMAN, you can use the following command:

sdk install java

This can be replaced with the version and respective identifier of Java you want to install.

For example, to install Java 11, you can use the following command:

sdk install java 11.0.19-amzn

SDKMAN downloads and installs the specified version of Java on your system. You can verify that the installation was successful by running the below command.

java -version

You can change the default java version in your system as well as it can be changed the java version in runtime(Change the Java version in the current shell session only)

If you need to set the installed java version as default, you can set it by responding to the below question

Do you want java 11.0.19-amzn to be set as default? (Y/n): Y
Switching between Java versions

Once you have installed multiple versions of Java using SDKMAN, you can easily switch between them using the below command.

sdk use java <version that u want to use>

Replace this with the version of Java you want to use with the identifier.

For example, to switch to Java 11, you can use the following command

sdk use java 11.0.19-amzn

With SDKMAN you can set the specified version of Java as the default version.

sdk default java <version>
Managing Java versions

You can switch Java version easily with SDKMAN. For that, you only need to install the required version via SDK man and use that java version as explained above.

 Uninstall unwanted JDK versions

You can easily uninstall the specified version of Java as below.

sdk uninstall java 17.0.0-zulu

SDKMAN simplifies the process of managing software development kits and saves developers time and effort.

If you are a Java developer, SDKMAN is a tool you should definitely check out.🤞🎉

Leave a comment