
You can select from a list of Java versions. Open a terminal window and enter this line:Īfter that, things are pretty straight-forward. The Unix approach is - well, it's typical Unix style. As far as I can see, using jEnv isn't much easier than the manual approach. I assume it does the trick, too, but I didn't test it. You can also install a Java version manager.

It looks similar to update-alternatives on Linux systems (see below), only it also covers tools like Gradle, Maven, and sbt, as well as languages like Groovy or Ceylon. I didn't test it yet, because after installing it noticed it doesn't support the Enterprise version of GraalVM, but it looks promising. It allows you to choose between Corretto, AdoptOpenJDK, GraalVM Community Edition, Liberica, OpenJDK, SapMachine, and even Zulu. It manages Java and a wide range of popular tools in the Java universe. SDKMAN! is a command-line tool for MaxOS, Linux and seral other operating systems based on Unix. I discovered this option recently, several months after writing the original article. Chances are you don't have to destroy the other Java version with the same version number: if MacOS finds a Java version matching the requested version number, it stops looking for other versions.

When you need it again, you must restore the Contents folder. That's a fairly reliable way to convince MacOS to ignore that Java installation. you're not interested in, and rename the Contents folder. Image published at under a CC0 license by an unknown artist. Navigate to the folder /Library/Java/JavaVirtualMachines, cd into the Java version Selecting a Java version. The only solution I found to do so is using brute force. You can't easily switch between GraalVM 11.0.9 and AdoptOpenJDK 11.0.9. That's not as arcane as it sounds: MacOS treats GraalVM as just another Java distribution. The bad news is you can't switch between identical versions provided by different vendors.

Replacing 15.0.1 with 15 does the trick, too, unless you want to distinguish between, say, 15.0.1 and 15.2.0. It doesn't have to be the precise version number. The catch is you have to unset (sic!) the JAVA_HOME variable. In a way, it's a good idea: just set the version number, and the operation system does the rest for you. Most of the time setting the PATH and JAVA_HOME worked. Older versions of OSX were pretty straightforward. However, if you need to switch between different versions, it doesn't suffice to set the environment variables PATH and JAVA_HOME. That's not a big deal if you need only one version of Java. Nowadays, most operating systems make a developer's life difficult by trying to help. Once upon a time, you could use Java without installing it.
