Java Version Management

Photo by Kris Atomic on Unsplash

Java Version Management

The right way to manage Java versions

ยท

3 min read

๐Ÿ‘‹๐Ÿป Introduction

Have you ever run into problems when you need to install different versions of Java or Maven? I have always found that installing another Java version and setting the JAVA_HOME and PATH variables very cumbersome. What if I tell you that there is a simple solution for you to manage your Java versions (and Maven and Gradle as well ๐Ÿ˜)

๐Ÿ› ๏ธ SDKMAN!!!

SDKMAN is a tool that allows you to manage multiple software development kits. It provides a large SDK list and it is completely free to use. You can check the SDK list provided by SDKMAN by going to https://sdkman.io/sdks.

๐Ÿ“ฅ Installation

SDKMAN is compatible with MacOS, Linux, and Windows. If you are a Windows user, there are two ways to install the SDKMAN, the WSL approach and the Git bash approach. If you are already using Git (If you are a developer, you should have Git! ๐Ÿ˜‰) just open up Git bash and run the following commands which are also compatible with Linux and MacOS.

  • Open a new terminal/command line and type, curl -s "https://get.sdkman.io" | bash

  • After that, you will see some on-screen instructions and then the installation is done.

  • After the installation, open a new terminal and run source "$HOME/.sdkman/bin/sdkman-init.sh"

  • Then verify whether the SDKMAN is installed to your matching by typing sdk version

๐Ÿงฉ Install Java with SDKMAN

After installing SDKMAN, open your terminal and run, sdk list java to see the list of available Java versions. After finding the version that you need to install, simply type, sdk install java <identifier> (e.g. sdk install java 21.0.2-amzn )

Now let's say you need to install Java 8 as well. Then simply type sdk install java 8.0.402-amzn But, now the issue is you have both Java 8 and Java 21. So how can you Java 8 as the default Java version and use Java 21 whenever you need it?

If you want to make any version as the default version, you can simply type sdk default java 8.0.402-amzn. But, if you simply want to use one Java version inside the terminal and not change the default Java version, you can simply type sdk use java 8.0.402-amzn and use that on the terminal where you have executed the above command.

Uninstalling Java versions using SDKMAN is also easy. You just have to type sdk uninstall java 8.0.402-amzn and then voila that Java version is gone.

Similar to Java, you can also install Maven, Gradle, and multiple other SDKs with SDKMAN. You don't have to install SDKs one by one. You just need one tool to manage all of your SDKs, and it's SDKMAN!!!

๐Ÿ“š References

  1. SDKMAN Documentation

  2. Introduction to Java by Eric Frick

ย