#1
If you're a Java developer working on Linux, setting up your development environment doesn't have to be complicated. In fact, with a tool called SDKMAN!, it becomes super simple to install and manage multiple versions of Java and other developer tools right from your terminal.
In this guide, you'll learn how to set up your Java environment on a Linux system using SDKMAN!. We’ll go through the installation step-by-step, show you how to install Java, and even switch between different versions
Let’s get started!

What Is SDKMAN?

SDKMAN! (short for Software Development Kit Manager) is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems. With SDKMAN!, you can easily install and switch between versions of Java, Maven, Gradle, Kotlin, and more.
Here’s why developers love it:
  • No need to manually download and set environment variables
  • Easily switch between different Java versions
  • Works great on Linux, macOS, and WSL

Prerequisites

Before you begin, make sure you have the following:
  • A Linux distribution (Ubuntu, Debian, Fedora, Arch, etc.)
  • A terminal application
  • curl installed (usually comes pre-installed on most systems)
  • zip and unzip installed (also commonly pre-installed)

Step 1: Install SDKMAN

First, open your terminal and run the following command to install SDKMAN:
curl -s "https://get.sdkman.io" | bash
This script downloads and installs SDKMAN! in your home directory.
After the installation is complete, you’ll see a message telling you to run:
source "$HOME/.sdkman/bin/sdkman-init.sh"
This command initializes SDKMAN! in your current shell session. To make it load automatically in future sessions, you can add that line to your .bashrc, .zshrc, or .profile file, depending on your shell.
To verify that SDKMAN! was installed correctly, run:
sdk version
You should see the version of SDKMAN! printed in the terminal.

Step 2: List Available Java Versions

Now that SDKMAN! is ready, you can list all the available Java versions:
sdk list java
This will display a long list of Java distributions and versions, including:
  • OpenJDK (by vendors like Temurin, Amazon, Oracle, etc.)
  • GraalVM, Zulu, Liberica, and more
Each version is tagged with identifiers like temurin, oracle, zulu, etc. You’ll also see labels like LTS (Long-Term Support) and installed.

Step 3: Install a Java Version

To install Java, pick one from the list. For example, to install Temurin OpenJDK 17 (LTS), you can run:
sdk install java 17.0.8-tem
You can replace the version and vendor based on your needs. The installation is automatic—SDKMAN! downloads, installs, and configures everything for you.
Once installed, you can check your current Java version:
java -version
If you see the correct version, you're good to go!

Step 4: Switch Between Java Versions

One of the best features of SDKMAN! is the ability to switch between Java versions easily.
Let’s say you’ve installed Java 8 and Java 17. To switch to Java 8, use:
sdk use java 17.0.8-tem
This change only affects your current terminal session. If you open a new terminal, it will revert to the default version.
To make a version the default for all sessions:
sdk default java 17.0.8-tem
This will update your global environment so that version is always used by default.

Step 5: Remove or Uninstall Java Versions (Optional)

To uninstall a Java version you no longer need, use:
sdk uninstall java 17.0.8-tem
This helps keep your system clean and frees up space.

Step 6: Set Up Java Home (Optional, Usually Automatic)

SDKMAN! automatically sets the JAVA_HOME environment variable when you switch versions. But if needed, you can also check or export it manually:
echo $JAVA_HOME
This will show you the path of the currently active Java version.
If you're using build tools like Maven or Gradle, they’ll often use this environment variable automatically.

image quote pre code