After some additional effort to figure this out, it turned out to be an easy fix. SDKman stores the JDKs in this folder:

C:\Users\yourUserName\.sdkman\candidates\java

When you issue the command

sdk default java 8.322.06.2-amzn

it copies the JDK from the java 8 folder

C:\Users\yourUserName\.sdkman\candidates\java\8.322.06.2-amzn

and pastes it into the current folder.

C:\Users\yourUserName\.sdkman\candidates\java\current

The idea is that you point your pc to the "current/" directory so that when you change java version with SDKman, the pc environment variable never needs to be updated.

But for the ide, instead of pointing it to the "current/" directory, you can point it directly to the JDK folder

C:\Users\yourUserName\.sdkman\candidates\java\8.322.06.2-amzn

You can specify the JDK for each project, P1 and P2, separately. So even if you change java version with SDKman, that only effects the "current/" directory, which the ides are no longer pointing at.

Since I did this, I dont have to change java version if I want to switch working on my java 8 project to working on my java 11 project. And that means I dont have to close my java 8 project to open my java 11 project. I can have them both open at the same time, and switch between them easily.

Answer from Steve T on Stack Overflow
🌐
SDKMAN!
sdkman.io › usage
Usage | SDKMAN! the Software Development Kit Manager
This can be done by setting the sdkman_auto_env=true in the SDKMAN configuration. Note that this will also reset any project-specific SDKs to their default version when leaving the directory.
Top answer
1 of 2
6

After some additional effort to figure this out, it turned out to be an easy fix. SDKman stores the JDKs in this folder:

C:\Users\yourUserName\.sdkman\candidates\java

When you issue the command

sdk default java 8.322.06.2-amzn

it copies the JDK from the java 8 folder

C:\Users\yourUserName\.sdkman\candidates\java\8.322.06.2-amzn

and pastes it into the current folder.

C:\Users\yourUserName\.sdkman\candidates\java\current

The idea is that you point your pc to the "current/" directory so that when you change java version with SDKman, the pc environment variable never needs to be updated.

But for the ide, instead of pointing it to the "current/" directory, you can point it directly to the JDK folder

C:\Users\yourUserName\.sdkman\candidates\java\8.322.06.2-amzn

You can specify the JDK for each project, P1 and P2, separately. So even if you change java version with SDKman, that only effects the "current/" directory, which the ides are no longer pointing at.

Since I did this, I dont have to change java version if I want to switch working on my java 8 project to working on my java 11 project. And that means I dont have to close my java 8 project to open my java 11 project. I can have them both open at the same time, and switch between them easily.

2 of 2
0

Inside IntelliJ versus outside IntelliJ

  • For running a project from within IntelliJ, you specify which JDK to use by configuring within IntelliJ.
  • The current default JDK set by SDKMAN! only applies to Java apps being executed on their own, outside IntelliJ.

Unfortunately, configuring which JDK to run your app within IntelliJ is complicated and confusing, requiring you to go spelunking through various buried panels.

These panels include some for the JDK, and some for the language level (which version of Java to target):

  • File | Project Structure | Project Settings | Project | SDK … and Language Level.
  • File | Project Structure | Project Settings | Project | Modules | Language Level.
  • Settings | Build, Execution, Deployment | Compiler | Java Compiler | Per-module bytecode version.

There may be others I don't recall at the moment. Search Stack Overflow to learn more.

If you are building a Web app in IntelliJ Ultimate edition, and running that app from within IntelliJ via an external application server such as Tomcat, Jetty, Glassfish, OpenLiberty, etc., then you need to also specify in another IntelliJ panel which JDK should be used to launch that app server.

If using Maven or Gradle, you need to specify language level there too.

Discussions

Can't switch Java version in mac - Stack Overflow
I did my due diligence and researched. I followed the following steps: /usr/libexec/java_home -V result was: Matching Java Virtual Machines (2): 11.0.13 (x86_64) "Oracle Corporation"... More on stackoverflow.com
🌐 stackoverflow.com
Why won't sdkman change my default java version? - Stack Overflow
This problem persisted after updating and upgrading sdkman, deleting .sdkman and reinstalling it, and uninstalling java packages and reinstalling them. me@myMachine myProject $ sdk default java 8.0... More on stackoverflow.com
🌐 stackoverflow.com
Switching versions of Java on Mac OSX
Not standard, but easier, try using sdkman. More on reddit.com
🌐 r/javahelp
10
1
January 7, 2023
Easily switch between java versions with SDKMAN! and 'j'
Gradle and toolchain is my personal best solution. So you don't need to configure your environment on each project if you have to manage different java version. And in addition it works very well together with sdkman. More on reddit.com
🌐 r/java
41
20
December 30, 2022
🌐
Wimdeblauwe
wimdeblauwe.com › blog › 2018 › 2018-09-26-switching-between-jdk-8-and-11-using-sdkman-
Switching between JDK 8 and 11 using SDKMAN - Wim Deblauwe
September 26, 2018 - For instance, if you made JDK 8 the default, then switch to JDK 11 in the current session by typing: ... 21:08 $ java -version openjdk version "11" 2018-09-25 OpenJDK Runtime Environment 18.9 (build 11+28) OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode) To set a permanent default, use the sdk default command. For instance, to make JDK 11 the default, type: ... If you want to be notified about new articles, as well as other interesting things I'm working on, join my mailing list!
🌐
Medium
medium.com › @zorozeri › manage-java-version-using-sdkman-including-maven-gradle-scala-kotlin-and-many-more-82532be9437e
Manage Java Version using SDKMAN! (including Maven, Gradle, Scala, Kotlin… and many more!) | by Ahmad Azeri Chandra Bhuana | Medium
January 16, 2025 - And you can use this Java version, using same switch sdk default command. For example on my case : ... And if you check using sdk list java, it would have >>> mark on it. ... Now, you might be wondering again. If we install Java using SDKMAN!, should we setup the JAVA_HOME again?
🌐
Abdelraouf Sabri
abd3lraouf.dev › home › blog › making sdkman java work with macos: a one-line fix
Making SDKMAN Java Work with macOS: A One-Line Fix - Abdelraouf Sabri
November 4, 2025 - The best part? When you switch Java versions with sdk use java 17, the integration automatically follows because it points to SDKMAN’s current symlink.
🌐
Mac Install Guide
mac.install.guide › java › sdkman
Install SDKMAN for Java on Mac · Mac Install Guide · 2026
Now when you cd into a directory containing .sdkmanrc, SDKMAN automatically switches to those versions. Leaving the directory restores your defaults. Limitation: The .sdkmanrc file must be in the current directory. SDKMAN does not search parent directories. If you're in a subdirectory, navigate to the project root or run sdk env manually. ... When teammates clone the repository and run sdk env install, they get the exact same SDK versions. This eliminates "works on my machine" problems.
Find elsewhere
🌐
Opensource.com
opensource.com › article › 22 › 3 › manage-java-versions-sdkman
Manage Java versions with SDKMan | Opensource.com
March 15, 2022 - SDKMan is like a package manager just for versions of Java. ... On Linux, you can install these using your package manager. On Fedora, CentOS Stream, Mageia, and similar: ... On Debian-based distributions, use apt instead of dnf. On macOS, use MacPorts or Homebrew.
🌐
JDriven
jdriven.com › blog › 2020 › 10 › Automatic-Switching-Of-Java-Versions-With-SDKMAN
Automatic Switching Of Java Versions With SDKMAN! - JDriven Blog
October 16, 2020 - In the next example we start with Java 15 as default version, next we run the env command in the directory with the .sdkmanrc file: ~ $ java -version openjdk version "15" 2020-09-15 OpenJDK Runtime Environment AdoptOpenJDK (build 15+36) Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.22.0, JRE 15 Mac OS X amd64-64-Bit Compressed References 20200922_45 (JIT enabled, AOT enabled) OpenJ9 - 1830b1927 OMR - 73d5e7623 JCL - 7e7613c015 based on jdk-15+36 ~ $ cd project-dir project-dir $ sdk env Using java version 11.0.8.hs-adpt in this shell.
🌐
Medium
medium.com › @annurahar › manage-various-java-versions-on-mac-osx-e6aee82c882c
Manage various Java versions on Mac OSX | by Annu Rahar | Medium
September 16, 2021 - SDKMAN sets this new version as default. Verify java version using java -version · In case new version 16 is not set to default, use below command to set sdk default java 16.0.2-open · Switch to directory where SDKMAN installed java at cd ~/.sdkman/candidates/java
🌐
GitHub
github.com › sdkman › sdkman-cli › issues › 877
Java version not swapping · Issue #877 · sdkman/sdkman-cli
February 22, 2021 - You switched accounts on another tab or window. Reload to refresh your session. ... There was an error while loading. Please reload this page. ... Hi all. Currently trying sdkman for the first time. I'm fairly new to programming and am bouncing between projects for some courses on Coursera and some tutorials on YouTube. I've run into a couple of problems with Java versions, so sdkman seemed the best solution.
Author   sdkman
Top answer
1 of 16
2562

First run /usr/libexec/java_home -V which will output something like the following:

Matching Java Virtual Machines (3):
1.8.0_05, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
1.6.0_65-b14-462, x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

Pick the version you want to be the default (1.6.0_65-b14-462 for arguments sake) then:

export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462`

or you can specify just the major version, like:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Now when you run java -version you will see:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Add the export JAVA_HOME… line to your shell’s init file.

For Bash (as stated by antonyh):

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

For Fish (as stated by ormurin)

set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8)

Updating the .zshrc file should work:

nano ~/.zshrc

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

Press CTRL+X to exit the editor Press Y to save your changes

source ~/.zshrc
echo $JAVA_HOME
java -version
2 of 16
608

This answer is an attempt to address: how to control java version system-wide (not just in currently running shell) when several versions of JDK are installed for development purposes on macOS El Capitan or newer (Sierra, High Sierra, Mojave). As far as I can tell, none of the current answers do that (*).

As a developer, I use several JDKs, and I want to switch from one to the other easily. Usually I have the latest stable one for general use, and others for tests. But I don't want the system (e.g. when I start my IDE) to use the latest "early access" version I have for now. I want to control system's default, and that should be latest stable.

The following approach works with Java 7 to 12 at least (early access at the time of this writing), with Oracle JDK or OpenJDK (including builds by AdoptOpenJDK produced after mid-October 2018).

Solution without 3rd party tools:

  • leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default.
  • To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command.

System launcher will use the JDK with highest version among those that have an Info.plist file.

When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).


Details of investigation in this gist.


(*) Current answers are either obsolete (no longer valid for macOS El Capitan or Sierra), or only address a single JDK, or do not address the system-wide aspect. Many explain how to change $JAVA_HOME, but this only affects the current shell and what is launched from there. It won't affect an application started from OS launcher (unless you change the right file and logout/login, which is tedious). Same for jenv, it's cool and all, but as far as I can tell it merely changes environment variables, so it has the same limitation.

🌐
Medium
medium.com › @ajeesh2705 › use-multiple-version-of-java-6219258bd8eb
Install Multiple Versions of Java in Mac using sdkman | by Ajeesh Sasidharan | Medium
August 7, 2019 - You can opt to have different java version for each module in IntelliJ. To set sdk, go to project structure (File -> Project Structure), change sdk on project or module level as shown below.
🌐
Mise-en-place
mise.jdx.dev › lang › java.html
Java | mise-en-place
May 18, 2026 - Download the unsupported version to a directory (e.g ~/.sdkman/candidates/java/21.0.1-open) ... mkdir ~/.local/share/mise/installs/java/21.0.1-open/Contents mkdir ~/.local/share/mise/installs/java/21.0.1-open/Contents/MacOS ln -s ~/.sdkman/candidates/java/21.0.1-open ~/.local/share/mise/installs/java/21.0.1-open/Contents/Home cp ~/.local/share/mise/installs/java/21.0.1-open/lib/libjli.dylib ~/.local/share/mise/installs/java/21.0.1-open/Contents/MacOS/libjli.dylib
🌐
Reddit
reddit.com › r/java › getting started with sdkman! – manage java, maven, gradle versions with ease
r/java on Reddit: Getting started with SDKMAN! – Manage Java, Maven, Gradle versions with ease
April 20, 2025 -

I put together a beginner-friendly guide on SDKMAN!, a super handy tool for managing parallel versions of Java SDKs, Maven, Gradle, and many other development tools right from your terminal.

If you've ever struggled with switching between Java versions for different projects, SDKMAN! can really simplify your workflow.

In the post, I cover:

  • What SDKMAN! is and why it’s useful.

  • How to install it.

  • How to install and switch between SDKs.

  • Tips for setting a default version.

Hope it helps someone!

🌐
Linux Uprising
linuxuprising.com › 2020 › 07 › how-to-install-switch-between-multiple.html
How To Install / Switch Between Multiple Java Versions Using SDKMAN - Linux Uprising Blog
June 17, 2021 - (using its installer, or offline using your own Java binaries), and how to manage and use multiple Java versions (easily setting a Java version as default, including setting the JAVA_HOME environment variable, or switching Java versions temporarily for the current terminal session, or only for a particular directory). 1. To get started, install the SDKMAN! command line interface. 2. List all the candidate Java versions.