Skip to content

Instantly share code, notes, and snippets.

@mherman22
Created May 23, 2025 10:00
Show Gist options
  • Save mherman22/c9b61ed4af2ecd796fb69952722cd38e to your computer and use it in GitHub Desktop.
Save mherman22/c9b61ed4af2ecd796fb69952722cd38e to your computer and use it in GitHub Desktop.

πŸ“š Managing Multiple Java Versions on macOS Using SDKMAN!

As you may often work with multiple projects or modules that require different versions of Java, it's essential to switch Java versions seamlessly. This guide shows you how to use SDKMAN! to install, manage, and switch between multiple Java versions on macOS.


Why SDKMAN?

  • 🧩 Easily install and manage Java and other JVM-based tools (e.g., Scala, Groovy).
  • πŸ› οΈ Automatically manages environment variables like $JAVA_HOME and $PATH.
  • πŸ§ͺ Provides a CLI for listing, installing, switching, and removing SDKs.

Install SDKMAN

  1. Open your terminal and run:

    curl -s "https://get.sdkman.io" | bash
  2. Follow on-screen instructions.

  3. Then activate it:

    source "$HOME/.sdkman/bin/sdkman-init.sh"
  4. Verify installation:

    sdk version

Install Different Java Versions

List available Java versions:

sdk list java

Install Java 12:

sdk install java 12.0.1.j9-adpt

Install Java 8:

sdk install java 8.0.222.j9-adpt

Switch Between Java Versions

Temporarily switch for current session:

sdk use java 8.0.222.j9-adpt

Set a global default:

sdk default java 12.0.1.j9-adpt

IntelliJ IDEA Integration

To use a specific Java version per module in IntelliJ:

  • Go to File β†’ Project Structure.
  • Assign a different SDK per module or project.

SDKMAN installs Java under:

~/.sdkman/candidates/java/<version>

To make it more accessible:

ln -s ~/.sdkman ~/sdkman

Then you can access it at ~/sdkman/....


Other Useful Commands

  • Uninstall a version:

    sdk uninstall java 8.0.222.j9-adpt
  • View all commands:

    sdk help

Summary

With SDKMAN, managing multiple Java versions becomes simple, clean, and developer-friendly. No more manually editing environment variables or hunting for JDK downloads β€” SDKMAN has your back.

πŸ§ͺ Perfect for teams or developers working across different Java-based projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment