DEV Community

Cover image for Streamline Your Java Development Workflow with SDKMAN
Duncan Lew
Duncan Lew

Posted on • Updated on • Originally published at duncanlew.Medium

Streamline Your Java Development Workflow with SDKMAN

Switching between Java versions can be as easy as running a single command

Do you have multiple versions of Java, Maven, Gradle, or other SDKs to manage? Are you tired of manually switching between different versions of these SDKs? SDKMAN to the rescue! SDKMAN is a command-line tool that allows you to quickly switch between various versions of SDKs, making it easier and more efficient to develop and test your applications. In this article, we'll discuss the benefits of using SDKMAN, provide some installation instructions, and explain how to use it to switch Java versions.

Benefits of using SDKMAN

Logo of SDKMAN
SDKMAN is a great tool for developers because it makes it easier to manage and switch between different versions of Java. By default, you can only have one version of Java installed on your computer at a time. With SDKMAN, you can easily switch between different Java versions without needing to uninstall or reinstall Java every time.

Another great benefit of SDKMAN is that it also works out of the box for other SDKs in the JVM ecosystem, like Maven, Gradle, Scala and SBT. You don’t have to install a different manager for each SDK.

In addition to that, SDKMAN makes it easier to keep your Java versions up-to-date. SDKMAN will automatically check for updates and notify you when new versions of Java are available. This saves you time and effort, as you don't need to manually search for updates

Finally, SDKMAN is a tool built in bash and is completely free to use. It's open-source and available for anyone to use.

Installation

Installing SDKMAN is very easy. All you need to do is run the following command in your terminal:

curl -s "https://get.sdkman.io" | bash
Enter fullscreen mode Exit fullscreen mode

If the command has been executed successfully, the output is going to look similar to this:
Installation result of SDKMAN

Once the command has been run, you can use SDKMAN to install and switch between different versions of Java. You might have to restart your Terminal before the sdk commands will work. To check whether SDKMAN works in your terminal after the installation, type the following command:

sdk version
Enter fullscreen mode Exit fullscreen mode

It should be able to output the version of SDKMAN like this:

SDKMAN 5.16.0
Enter fullscreen mode Exit fullscreen mode

Installing Java versions

SDKMAN makes it very easy to install different Java versions. To list all available Java versions that you can install, simply run the following command:

sdk list java
Enter fullscreen mode Exit fullscreen mode

This will list all the available versions of Java that you can install. If you want to install Java 11 from the vendor Temurin, you can look for the identifier in this list which is: 11.0.17-tem. Type q to exit the list. Using the identifier for the Java version you want to install, run the following installation command:

sdk install java 11.0.17-tem
Enter fullscreen mode Exit fullscreen mode

After successfully installing Java 11, the output will look like this:
Installation result for Java 11

If you need to install Java 17 from Temurin, it’s as easy as copying the identifier from the output command of sdk list java and placing it in the sdk install command:

sdk install java 17.0.5-tem
Enter fullscreen mode Exit fullscreen mode

Switching Java versions

To switch between Java versions, you need to look for the identifier of your Java version in sdk list java and copy that value to switch to. If you’d like to switch to Java 11 of Temurin, run the following command:

sdk use java 11.0.17-tem
Enter fullscreen mode Exit fullscreen mode

If you’d like to switch to Java 17 of Temurin, this would be the correct command:

sdk use java 17.0.5-tem
Enter fullscreen mode Exit fullscreen mode

Making a specific Java version the default

If you’d like to make a specific Java version the default, like version 17 of Temurin, you can run the following command:

sdk default java 17.0.5-tem
Enter fullscreen mode Exit fullscreen mode

How about Maven, Grade, and the rest?

We’ve seen how to install and switch between Java versions. But how would you know which SDKs are supported? No worries! The complete list of SDKs supported by SDKMAN can be found here: https://sdkman.io/sdks. How do you install and switch between other JVM-based SDKs like Maven, Grade, and the rest? The principle is the same for Java. You simply have to replace the Java and identifier command with the one the SDK you want to use:

sdk list maven
sdk install maven <version-identifier>
Enter fullscreen mode Exit fullscreen mode

Conclusion

SDKMAN streamlines the management of all the SDKs that you’d need in the JVM ecosystem. We’ve covered how to easily install and switch Java versions and also how to do that for other SDKs that you’d need. SDKMAN is definitely a tool worth checking out and can help you save time and effort in the process. This is especially helpful for teams that are working on multiple projects with different SDK version requirements. Happy coding! 😎




If the content was helpful, feel free to support me here:

Buy Me A Coffee

Top comments (0)