Explain Codes LogoExplain Codes Logo

See all the Java versions installed on Mac

java
java-management
java-versions
mac-os
Alex KataevbyAlex Kataev·Nov 21, 2024
TLDR

For a rapid recap of all installed Java versions on your Mac, deploy below command in your Terminal:

/usr/libexec/java_home -V

It will furnish a succinct display of paths corresponding to both Oracle and OpenJDK implementations. This quick trick hoists up all Java runtimes registered in your system like Jack-in-the-box.

Locate unidentified Java distributions

While the above command fetches an orderly list of recognized Java installations, some outliers might evade the radar. A Java distribution manually ballooned from a ZIP or TAR.GZ format may not register with the system just as Java versions installed via Homebrew might slip under the radar of /usr/libexec/java_home -V.

Here, an illuminating command comes into play to lay bare these hidden Java versions as:

mdfind -name 'java' | grep '/bin/java$' # Sherlock Holmes mode - finding the hidden Clue(do) of java.

Harnessing the spotlight search capability of mdfind, the macOS-native speedy file scanning utility, and filtering via grep curates a list of those Java distributions installed manually or by other methods, revealing even the hide-and-seek champs of your system.

Package handlers to the rescue!

SDKMAN!, Homebrew, and MacPorts can rise to the occasion if handling multiple Java environments feels like herding cats. These package managers are dexterous at not only installing different Java versions but also at playing switcheroo between them. It's your pocket-sized Juggler!

Dud-proof your Java management with jEnv

To stop juggling and start enjoying your array of Java installations, give 'jEnv' a whirl! This nifty tool binds your environment variables to your projects, making the switch between different Java versions as smooth as a ballroom dance. Ideal for developers moonlighting as project managers!

Embrace the open-source spirit—Community Java builds

Staying ahead of the Java curve is no Herculean task! Frequent the open-source monoliths like Adoptium and AdoptOpenJDK, offering a platter of community-driven OpenJDK builds that come with an easy install option.