SDKMAN (Software Development Kit Manager) is a command-line tool that allows you to manage multiple versions of Java and other SDKs easily. Here’s how you can install and manage multiple Java versions using SDKMAN:
Step 1: Install SDKMAN
- Open your terminal.
- Run the following command to install SDKMAN:
curl -s "https://get.sdkman.io" | bash
- Follow the instructions provided during the installation process, which might ask you to update your shell configuration.
-
Reload your terminal or execute:
source "$HOME/.sdkman/bin/sdkman-init.sh"
- Verify the installation:
sdk version
If installed correctly, it will display the version of SDKMAN you just installed.
Step 2: List Available Java Versions
To list all available Java versions:
sdk list java
This will display a list of Java distributions and their versions.
Step 3: Install a Specific Java Version
To install a desired Java version, use the following command:
sdk install java <version>
For example, to install OpenJDK 21:
sdk install java 21-open
Once installed, it will set this version as the default one automatically.
Step 4: Use a Specific Version
- To see all installed versions, use:
sdk list java
- To switch to a specific version:
sdk use java <version>
For example:
sdk use java 17-open
This will only apply to your current terminal session.
Step 5: Set a Default Version
To make a specific Java version the default across all terminal sessions:
sdk default java <version>
For instance:
sdk default java 21-open
Step 6: Check Active Java Version
To check the currently active Java version:
java -version
Managing Installed Versions
- To see installed versions:
sdk list java
- To uninstall an old or unused version:
sdk uninstall java <version>
Additional Tips
- SDKMAN can also manage other SDKs like Maven, Gradle, and Kotlin.
- To update SDKMAN itself:
sdk update
- To update all installed SDKs:
sdk upgrade
By following these steps, you can easily install, switch, and manage multiple Java versions using SDKMAN!