You might want to have more than one JDK on your Mac and run different programs with different JDK versions as it is with me.

The easiest and safest way I've found is as follows.

First, download the JDK archive (not the DMG installation file) from Oracle, for example version 11:

Note: you'll need an Oracle account to do that.

Look for the file "macOS Compressed Archive".

Once downloaded, extract this file to a directory that you won't wipe off easily. I've chosen a directory "tools" in my home directory. You'll end up with a java binary such as:

/Users/toli/tools/jdk-11.0.10.jdk/Contents/Home/bin/java -version
java version "11.0.10" 2021-01-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)

Then open Applications/ and look for:

  <!-- to use a specific Java version (instead of the platform's default) uncomment one of the following options,
                                    or add a VM found via $/usr/libexec/java_home -V

Note that after the end of the commented out area I've added:


That's all. Now you can easily change the Java version for your eclipse, maven or any other command easily on Mac without worrying that you can break irreversible something.