Yes you can.

You should use the SDK Man software. curl -s "https://get.sdkman.io" | bash

When doing the sdk list java, you will get a screen like this:

=============================================================================== Available Java Versions for Linux 64bit ================================================================================ Vendor | Use | Version | Dist | Status | Identifier -------------------------------------------------------------------------------- Corretto | | 21.0.2 | amzn | | 21.0.2-amzn
| | 21.0.1 | amzn | | 21.0.1-amzn
| | 17.0.10 | amzn | | 17.0.10-amzn
| | 17.0.9 | amzn | | 17.0.9-amzn
| | 11.0.22 | amzn | | 11.0.22-amzn
| | 11.0.21 | amzn | | 11.0.21-amzn
| | 8.0.402 | amzn | | 8.0.402-amzn
| | 8.0.392 | amzn | | 8.0.392-amzn Dragonwell | | 17.0.9 | albba | | 17.0.9-albba
| | 11.0.21 | albba | | 11.0.21-albba
| | 11.0.20 | albba | | 11.0.20-albba
| | 8.0.402 | albba | | 8.0.402-albba
| | 8.0.392 | albba | | 8.0.392-albba
| | 8.0.382 | albba | | 8.0.382-albba Gluon | | 22.1.0.1.r17 | gln | | 22.1.0.1.r17-gln
| | 22.1.0.1.r11 | gln | | 22.1.0.1.r11-gln GraalVM CE | | 21.0.2 | graalce | | 21.0.2-graalce
| | 21.0.1 | graalce | | 21.0.1-graalce
| | 17.0.9 | graalce | | 17.0.9-graalce GraalVM Oracle| >>> | 21.0.2 | graal | installed | 21.0.2-graal
| | 21.0.1 | graal | | 21.0.1-graal
| | 17.0.10 | graal | | 17.0.10-graal
| | 17.0.9 | graal | | 17.0.9-graal

First of all you should install all the different version by: sdk install java yourVersion like sdk install java 21.0.1-graalce or sdk install java 17.0.9-graalce or sdk install java 23.ea.12-open.

This allows you to go to a directory and do sdk use java 21.0.1-graalce.

This will activate the JDK 21 version of the GraalVM CommunityEdition (CE). You can do this for different version in different directories.

Answer from Mahir Zukic on Stack Overflow
🌐
SDKMAN!
sdkman.io › usage
Usage | SDKMAN! the Software Development Kit Manager
Setting java 21.0.4-tem as default. Need a specific version of an SDK?
Top answer
1 of 3
4

Yes you can.

You should use the SDK Man software. curl -s "https://get.sdkman.io" | bash

When doing the sdk list java, you will get a screen like this:

=============================================================================== Available Java Versions for Linux 64bit ================================================================================ Vendor | Use | Version | Dist | Status | Identifier -------------------------------------------------------------------------------- Corretto | | 21.0.2 | amzn | | 21.0.2-amzn
| | 21.0.1 | amzn | | 21.0.1-amzn
| | 17.0.10 | amzn | | 17.0.10-amzn
| | 17.0.9 | amzn | | 17.0.9-amzn
| | 11.0.22 | amzn | | 11.0.22-amzn
| | 11.0.21 | amzn | | 11.0.21-amzn
| | 8.0.402 | amzn | | 8.0.402-amzn
| | 8.0.392 | amzn | | 8.0.392-amzn Dragonwell | | 17.0.9 | albba | | 17.0.9-albba
| | 11.0.21 | albba | | 11.0.21-albba
| | 11.0.20 | albba | | 11.0.20-albba
| | 8.0.402 | albba | | 8.0.402-albba
| | 8.0.392 | albba | | 8.0.392-albba
| | 8.0.382 | albba | | 8.0.382-albba Gluon | | 22.1.0.1.r17 | gln | | 22.1.0.1.r17-gln
| | 22.1.0.1.r11 | gln | | 22.1.0.1.r11-gln GraalVM CE | | 21.0.2 | graalce | | 21.0.2-graalce
| | 21.0.1 | graalce | | 21.0.1-graalce
| | 17.0.9 | graalce | | 17.0.9-graalce GraalVM Oracle| >>> | 21.0.2 | graal | installed | 21.0.2-graal
| | 21.0.1 | graal | | 21.0.1-graal
| | 17.0.10 | graal | | 17.0.10-graal
| | 17.0.9 | graal | | 17.0.9-graal

First of all you should install all the different version by: sdk install java yourVersion like sdk install java 21.0.1-graalce or sdk install java 17.0.9-graalce or sdk install java 23.ea.12-open.

This allows you to go to a directory and do sdk use java 21.0.1-graalce.

This will activate the JDK 21 version of the GraalVM CommunityEdition (CE). You can do this for different version in different directories.

2 of 3
0

For support purposes I have multiple versions of Java installed all the time. Namely, I have:

  • Oracle Java 6
  • Oracle Java 7
  • Oracle Java 8
  • Oracle Java 11
  • OpenJDK 11
  • OpenJDK 17
  • OpenJDK 21

Yes, I have two Java 11 from different sources.

You can download the packages separately and decompress them. This stategy avoids using the installers since they will try to manage the system properties and set/reset their own versions as the "default one". You probably want to manage the default manually, not automatically.

Now, your folder will look like:

Copyjdk1.6.0_34
jdk1.7.0_40
jdk1.8.0_51
openjdk-11+28
java -> jdk-11+28  (this is a symlink)
...

The PATH variable includes the symlink folder only. This way I decide which java version to use by switching the java symlink -- that is pointing in this example to the OpenJDK 11. If I want to use Java 6, I can repoint the symlink by doing:

Copyrm java
ln -s jdk1.6.0_34 java

Easy, isn't it?

Finally, most IDEs can make this change a lot easier, but I wanted to show you the manual way of doing things, so you can understand there's no magic behind it.

Discussions

How do you change java version using SDKMAN without needing to close Intellij IDEA first? - Stack Overflow
Note: I am using the Community Edition of IntelliJ IDEA, version 2022.3.2 · Edit: Here is a snapshot of the Project Settings that shows picking the JDK from the file system. ... Save this answer. ... Show activity on this post. After some additional effort to figure this out, it turned out to be an easy fix. SDKman stores the JDKs in this folder: ... The idea is that you point your pc to the "current/" directory so that when you change java ... More on stackoverflow.com
🌐 stackoverflow.com
Why won't sdkman change my default java version? - Stack Overflow
So i just removed all Java versions installed on the updates cause I need only to use the sdkman. ... So after removed all java: i run java -version i found there is no java anymore. ... And thats it now i can change versions again with sdkman. More on stackoverflow.com
🌐 stackoverflow.com
How do I switch between Java versions?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
13
11
March 20, 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 - To temporarily switch to another version, use the sdk use command. 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 ...
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.

🌐
Baeldung
baeldung.com › home › devops › guide to sdkman!
Guide to SDKMAN! | Baeldung
November 13, 2025 - Let’s say we want to install the newest build of Java 14 from Azul Zulu. Therefore, we copy its identifier, which is the version from the table, and we add it as an argument in the install command: $ sdk install java 14.0.2-zulu Downloading: java 14.0.2-zulu In progress...
🌐
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 - Run this in the directory for which you want to use a custom Java version: sdk env init A file called .sdkmanrc has now been generated in this directory. Open it and change the value of java= to the Java version identifier you want to use, e.g. 11.0.8.hs-adpt for AdoptOpenJDK 11.0.8.
Find elsewhere
🌐
Opensource.com
opensource.com › article › 22 › 3 › manage-java-versions-sdkman
Manage Java versions with SDKMan | Opensource.com
March 15, 2022 - Instead you can type sdk install java 11 and then press Tab a few times to get the options. Alternately, you can just install the default latest version:
🌐
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 - We first change it to Java 11 and then run env init to set Java 11 as default version for our projec directory: project-dir $ 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) project-dir $ sdk use java 11.0.8.hs-adpt Using java version 11.0.8.hs-adpt in this shell.
🌐
JetBrains
jetbrains.com › help › idea › sdk.html
SDKs | IntelliJ IDEA Documentation
If the JDK is installed on your computer but not defined in the IDE, select Add SDK from disk and specify the path to the JDK home directory (for example, /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk). If you don't have the necessary JDK on your computer, select Download JDK. In the next dialog, specify the JDK vendor, version, change the installation path if required, and click Download.
🌐
Baeldung
baeldung.com › home › ide › how to change the java version in an intellij project
How to Change the Java Version in an IntelliJ Project | Baeldung
June 20, 2025 - To demonstrate, let’s set the Java SDK version as 17 along with the Language level as 21: When we build or compile the project, we’ll get an error or warning message similar to: To fix this message, we should set the SDK to be the same or higher than the Language level. Alternatively, we can change ...
🌐
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 - If this is the first time Java is installed using SDKMAN! it will be used as the default Java. You can check it by run usual java -version command : ... Now, let’s install the second Java version. This time I’ll choose Vendor Oracle with Version 21.0.5. The command would be : ... You’ll be asked whether you want to use this new installed version as the default or not. If yes, then type Y and hit enter. ... Once you check the version, it is already changed!
🌐
Reinhard
blog.reinhard.codes › 2021 › 06 › 18 › automatic-switching-of-java-sdk-versions
Automatic switching of Java SDK versions | reinhard.codes
# Enable auto-env through the sdkman_auto_env config # Add key=value pairs of SDKs to use below java=8.0.222.hs-adpt · Now you can issue the command sdk env if you want to switch to this version, and if you want to go back to your default you can revert using the command skd env clear.
🌐
Twilio
twilio.com › blog › sdkman-work-with-multiple-versions-java
Using SDKMAN! to work with multiple versions of Java
April 3, 2020 - For IntelliJ IDEA this can be done from the “Project Structure” dialog. Either choose an existing version from the drop-down, or add a new Java version by selecting “New...” from the “Project SDK” section:
🌐
HappyCoders.eu
happycoders.eu › java › how-to-switch-multiple-java-versions-windows
How to Change Java Versions in Windows (up to Java 25)
June 11, 2025 - As the default version, I recommend the current release version, Java 24. Accordingly, you should make the following settings: The top list ("User variables") should not contain any Java-related entries. The lower list ("System variables") should contain an entry "JAVA_HOME = C:\Program Files\Java\jdk-24". If this entry does not exist, you can add it with "New…". If it exists but points to another directory, you can change it with "Edit…".
🌐
My Developer Planet
mydeveloperplanet.com › 2022 › 04 › 05 › how-to-manage-your-jdks-with-sdkman
How to Manage Your JDKs With SDKMAN – My Developer Planet
April 5, 2022 - Answer with no, JDK 17 is the latest LTS version of Java and should be ok to be the default. $ sdk install java 11.0.14-tem Downloading: java 11.0.14-tem In progress... ... Repackaging Java 11.0.14-tem... Done repackaging... Installing: java 11.0.14-tem Done installing! Do you want java 11.0.14-tem to be set as default? (Y/n): n · If you change your mind, and you still want JDK 11 to be the default, then you can do so by means of the default command.
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.