Master Multi‑Version Java Management with SDKMAN: Install, Switch, and Upgrade
This article explains why managing multiple Java versions is necessary, introduces SDKMAN as a cross‑platform tool, and provides step‑by‑step commands for installing, listing, switching, setting defaults, flushing caches, and uninstalling SDKMAN on Unix‑like systems and Windows.
Introduction
Java releases new versions frequently; developers often need to handle several versions simultaneously for new features or project compatibility. Oracle's licensing changes after Java 11 also motivate the use of OpenJDK distributions.
Since Java 11 Oracle requires a commercial license for production use, many developers prefer OpenJDK alternatives.
Managing a single Java environment variable is trivial, but handling multiple versions with traditional methods is cumbersome.
Multi‑Version Java Management
Common solutions include:
Jabba ( https://github.com/shyiko/jabba )
jenv ( https://github.com/jenv/jenv )
SDKMAN ( https://sdkman.io/ )
This guide focuses on using SDKMAN to simplify Java version management.
What Is SDKMAN?
SDKMAN is a command‑line tool for Unix‑like systems that manages parallel versions of software development kits such as Java, Groovy, Scala, Kotlin, Ant, Gradle, and more.
It provides commands to install, switch, remove, and list candidates.
Installing SDKMAN
Run the following commands in a terminal: $ curl -s "https://get.sdkman.io" | bash Follow the prompts, then initialize the environment: $ source "$HOME/.sdkman/bin/sdkman-init.sh" Verify the installation:
$ sdk versionSDKMAN checks for updates each time sdk version runs; press y to upgrade.
If zip or unzip are missing, install them: $ sudo apt-get install zip unzip The default installation directory is $HOME/.sdkman, but you can change it by setting SDKMAN_DIR before installation.
$ export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bashSDKMAN Usage Tutorial
Start with the help command:
$ sdkman helpListing Candidates
$ sdk listTo see Java versions:
$ sdk list javaInstalling a Version
Install the latest Java 13.0.1.j9: $ sdk install java 13.0.1.j9 Use the identifier shown by sdk list java if the version label is unavailable.
Checking Current Version
$ sdk current javaSwitching Versions
$ sdk use java 12.0.2.j9-adptSetting Default Version
$ sdk default java jdk1.8.0_162.jdkUninstalling a Version
$ sdk uninstall java 12.0.2.j9-adptUpgrading a Candidate
$ sdk upgrade javaFlushing Caches
Clear broadcast messages, archives, and temporary files:
$ sdk flush broadcast $ sdk flush archives $ sdk flush tempUse sdk help anytime to view available commands.
Uninstalling SDKMAN
Backup and remove the SDKMAN directory:
$ tar zcvf ~/sdkman-backup_$(date +%F-%kh%M).tar.gz -C ~/ .sdkman
$ rm -rf ~/.sdkmanDelete the initialization lines from your shell profile files (e.g., .bashrc, .zshrc).
SDKMAN on Windows
The SDKMAN website provides a Windows‑compatible solution; users can follow the instructions there.
Soul‑Searching Questions
What Java version are you currently using?
Do you experiment with new features in newer releases?
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
