Friday, February 14, 2025

How to Install and Setting Up SDKMAN on Ubuntu/Manjaro Linux


SDKMAN is fantastic command-line tool simplifies SDK management, allowing you to effortlessly install, update, manage, and switch between multiple versions of development kits right from your terminal. Say goodbye to manual downloads and environment variable headaches!

This guide will walk you through the straightforward process of installing SDKMAN! on both Ubuntu/Debian-based systems, including the latest Ubuntu 24.04 LTS (Noble Numbat), and Manjaro (Arch-based) distributions. We'll also demonstrate how to install a specific Java version using SDKMAN!, empowering you to take control of your development environment.

To supercharge your setup, we've even included details on an automation script to streamline the entire installation process. Let's dive in! 🚀

Prerequisites: Essential Tools for SDKMAN!

Before we install SDKMAN!, let's ensure your system has the necessary tools. These are essential for downloading and managing SDKMAN! and its components:

  • curl: This command-line tool is your download workhorse. SDKMAN! uses curl to fetch its installation script and SDK packages.
  • zip / unzip: These utilities are crucial for handling compressed SDK archives. SDKMAN! relies on them to extract the SDKs you install.

Checking and Installing Prerequisites:

Most Linux distributions come with curl pre-installed. Let's verify and install any missing components:

For Ubuntu/Debian (including Ubuntu 24.04 LTS):

Open your terminal and run the following command to update your package list and install the prerequisites:

Bash
sudo apt update && sudo apt install curl zip unzip

For Manjaro (Arch-based):

Use pacman, Manjaro's package manager, to install the necessary tools:

Bash
sudo pacman -Syu curl zip unzip

You'll be prompted to enter your password to authorize the installation. Once these commands are executed, you're ready to proceed with SDKMAN! installation.

Step-by-Step: Installing SDKMAN!

The installation process for SDKMAN! is remarkably consistent across Linux distributions. Follow these steps for both Ubuntu/Debian and Manjaro:

  1. Open Your Terminal: Launch your terminal application.

  2. Execute the Installation Command: Paste the following command into your terminal and press Enter:

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

    This command uses curl to download the SDKMAN! installation script directly from the official website and executes it using bash.

  3. Follow the On-Screen Instructions: The installation script will guide you through the process. Typically, it involves:

    • Downloading SDKMAN!: The script will download the SDKMAN! archive to your system.
    • Extracting SDKMAN!: It will then extract the archive to the ~/.sdkman directory in your home directory.
    • Initializing SDKMAN!: The script will modify your shell configuration files (~/.bashrc, ~/.zshrc, etc.) to initialize SDKMAN! in your terminal sessions.
  4. Open a New Terminal Session: For the changes to take effect, you need to open a new terminal window or session. Alternatively, you can source your shell configuration file manually:

    For Bash:

    Bash
    source ~/.bashrc
    

    For Zsh:

    Bash
    source ~/.zshrc
    
  5. Verify Installation: To confirm that SDKMAN! is installed correctly, run:

    Bash
    sdk version
    

    This command should display the installed SDKMAN! version. If you see the version number, congratulations! SDKMAN! is successfully installed on your system.

Installing Java with SDKMAN!

Now that SDKMAN! is set up, let's install a specific Java version. SDKMAN! makes this incredibly easy.

  1. List Available Java Versions: To see the available Java versions that SDKMAN! can install, use the following command:

    Bash
    sdk list java
    

    This will display a list of Java distributions (like GraalVM CE, Liberica, Temurin, etc.) and their available versions. You'll see something similar to:

    ================================================================================
    Available Java Versions for Linux x86_64
    ================================================================================
    Distro     | Version      | Status     | Identifier
    --------------------------------------------------------------------------------
    GraalVM CE | 21.0.2-java21 |            | java-21.0.2-graalce
    GraalVM CE | 17.0.10      |            | java-17.0.10-graalce
    GraalVM CE | 11.0.22      |            | java-11.0.22-graalce
    Liberica   | 22.ea.25     |            | 22.ea.25-librca
    Liberica   | 21.0.2       |            | 21.0.2-librca
    Liberica   | 20.0.2       |            | 20.0.2-librca
    ...
    
  2. Install a Specific Java Version: Let's say you want to install Temurin Java 21.0.2. Identify the "Identifier" from the list (in this case, it's likely java-21.0.2-tem). Then, use the sdk install command followed by the identifier:

    Bash
    sdk install java 21.0.2-tem
    

    SDKMAN! will download and install the specified Java version.

  3. Set a Default Java Version (Optional): If you want to make this newly installed Java version your default, use:

    Bash
    sdk default java 21.0.2-tem
    
  4. Verify Java Installation: Check your installed Java version:

    Bash
    java -version
    

    This should now reflect the Java version you just installed through SDKMAN!.

Automation Script for Streamlined Installation

To make the entire process even smoother, especially if you're setting up multiple machines or want a repeatable process, consider using an automation script. Here's a basic example using bash:

Bash
#!/bin/bash

# Update package lists and install prerequisites (Ubuntu/Debian)
if grep -q "Ubuntu" /etc/os-release || grep -q "Debian" /etc/os-release; then
  sudo apt update && sudo apt install -y curl zip unzip
fi

# Install prerequisites (Manjaro/Arch)
if grep -q "Manjaro" /etc/os-release || grep -q "Arch" /etc/os-release; then
  sudo pacman -Syu --noconfirm curl zip unzip
fi

# Install SDKMAN!
curl -s "https://get.sdkman.io" | bash

echo "SDKMAN! Installation Complete. Open a new terminal or run 'source ~/.bashrc' or 'source ~/.zshrc'"

How to use this script:

  1. Save the script: Save the code above to a file, for example, install_sdkman.sh.
  2. Make it executable: Give the script execute permissions: chmod +x install_sdkman.sh
  3. Run the script: Execute the script in your terminal: ./install_sdkman.sh

This script automates the prerequisite installation and SDKMAN! setup, saving you time and effort. You can further extend this script to automatically install specific Java versions or other SDKs as needed.

Conclusion

SDKMAN! is an indispensable tool for Java, Kotlin, and JVM developers. It drastically simplifies the management of multiple SDK versions, allowing you to switch between them effortlessly and keep your development environment clean and organized.

0 comments:

Post a Comment