Install SDKMAN! - lightblueseas/linuxstuff GitHub Wiki
Install SDKMAN!
Installation of SDKMAN! Package Manager
SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits (SDKs) on Unix-based systems.
Prerequisites
Ensure that you have curl and zip installed on your system before proceeding.
Ubuntu/Debian-based Systems
To install curl
and zip
, run:
sudo apt install curl zip unzip -y
Manjaro (Arch-based Systems)
For Manjaro, install the required dependencies using:
sudo pacman -Syu curl zip unzip --noconfirm
Installing SDKMAN!
Once the prerequisites are installed, install SDKMAN! using the following command:
curl -s "https://get.sdkman.io" | bash
After the installation is complete, open a new terminal or initialize SDKMAN! manually with:
source "$HOME/.sdkman/bin/sdkman-init.sh"
To verify that SDKMAN! is installed correctly, run:
sdk version
If successful, you should see output similar to:
script: 5.18.2
native: 0.4.6
For more details, refer to the official SDKMAN! installation guide.
Installing a Specific Java Version
To list all available Java versions, run:
sdk list java
This command will display a list of available Java versions. Copy the identifier from the Identifier column of your preferred version.
For example, to install Java 21.0.4-tem, use:
sdk install java 21.0.4-tem
During installation, you may be prompted to set this version as the default. Choose n
if you do not want to make it the default version.
Automated Installation Script for SDKMAN! and Java
To automate the installation of SDKMAN! and a Java version, you can use the following script. This script:
✅ Detects the OS (Ubuntu/Debian or Manjaro/Arch-based)
✅ Installs required dependencies (curl
, zip
, unzip
)
✅ Installs SDKMAN!
✅ Prompts the user for a Java version and installs it
Installation Script
Save the following script as install_sdkman.sh
:
#!/bin/bash
# Automated SDKMAN! Installation Script
# Supports Ubuntu/Debian and Manjaro (Arch-based) systems
set -e # Exit on error
# Function to check OS type
detect_os() {
if [ -f "/etc/os-release" ](/lightblueseas/linuxstuff/wiki/--f-"/etc/os-release"-); then
. /etc/os-release
echo "$ID"
else
echo "Unsupported OS"
exit 1
fi
}
# Function to install dependencies
install_dependencies() {
local os_type=$1
echo "Installing dependencies..."
case "$os_type" in
ubuntu|debian)
sudo apt update && sudo apt install -y curl zip
;;
manjaro|arch)
sudo pacman -Syu --noconfirm curl zip
;;
*)
echo "Unsupported OS detected."
exit 1
;;
esac
echo "Dependencies installed successfully."
}
# Function to install SDKMAN!
install_sdkman() {
echo "Installing SDKMAN!..."
curl -s "https://get.sdkman.io" | bash
# Initialize SDKMAN!
source "$HOME/.sdkman/bin/sdkman-init.sh"
# Verify installation
if sdk version; then
echo "SDKMAN! installed successfully."
else
echo "SDKMAN! installation failed."
exit 1
fi
}
# Function to install a specific Java version
install_java() {
local java_version=$1
echo "Installing Java version: $java_version..."
sdk install java "$java_version"
echo "Java $java_version installed successfully."
}
# Detect OS
OS_TYPE=$(detect_os)
echo "Detected OS: $OS_TYPE"
# Install dependencies
install_dependencies "$OS_TYPE"
# Install SDKMAN!
install_sdkman
# Prompt for Java version installation
read -p "Enter Java version to install (e.g., 21.0.4-tem): " JAVA_VERSION
if [ -n "$JAVA_VERSION" ](/lightblueseas/linuxstuff/wiki/--n-"$JAVA_VERSION"-); then
install_java "$JAVA_VERSION"
else
echo "Skipping Java installation."
fi
echo "Installation process completed successfully!"
How to Use the Script
-
Save the script to a file:
nano install_sdkman.sh
Paste the script into the file and save it (
CTRL+X
, thenY
, thenENTER
). -
Make the script executable:
chmod +x install_sdkman.sh
-
Run the script:
./install_sdkman.sh
This script ensures that SDKMAN! and the Java version of your choice are installed correctly and configured properly. 🚀