When working with Java projects, you’ll often need to install and manage multiple versions of Java and build tools like Maven. Instead of manually downloading tarballs and updating environment variables, SDKMAN!
provides an easy way to install, manage, and switch between different versions of development kits on Linux and macOS.
In this post, I’ll walk you through installing Java and Maven using SDKMAN on a Linux machine.
What is SDKMAN?
SDKMAN (Software Development Kit Manager) is a tool for managing parallel versions of multiple software development kits. It supports Java, Maven, Gradle, Kotlin, Scala, and more.
Some of the benefits of using SDKMAN:
Install and switch between multiple versions easily.
No need to manually configure environment variables.
Consistent setup across development environments.
Step 1: Install SDKMAN
Open your terminal and run the following command to install SDKMAN:
curl -s "https://get.sdkman.io" | bash
Once the installation completes, initialize it by running:
source "$HOME/.sdkman/bin/sdkman-init.sh"
To verify the installation, check the version:
sdk version
If it prints out a version number, SDKMAN is ready to use.
Step 2: Install Java
SDKMAN supports different Java distributions (AdoptOpenJDK, Temurin, Amazon Corretto, Zulu, etc.).
List available Java versions:
sdk list java
Pick the one you want to install. For example, to install Temurin JDK 21 (LTS):
sdk install java 21-tem
To set a default version:
sdk default java 21-tem
Verify the installation:
java -version
Step 3: Install Maven
Next, install Maven with SDKMAN:
sdk install maven
To check available versions:
sdk list maven
To set a specific version:
sdk install maven 3.9.9
sdk default maven 3.9.9
Verify Maven installation:
mvn -version
Step 4: Managing Versions
One of the best parts of SDKMAN is version switching.
For example:
sdk install java 17-tem
sdk use java 17-tem
You can quickly switch between Java 17 and Java 21 without touching environment variables.
Similarly, you can do the same for Maven or other tools.
Conclusion
Using SDKMAN makes it simple to manage Java, Maven, and many other SDKs on Linux. No more messing around with PATH variables or manual installations. With just a few commands, you can install, switch, and maintain multiple versions of your tools.
If you’re working on multiple Java projects with different requirements, SDKMAN is a must-have for your development environment.
Top comments (0)