See all the Java versions installed on Mac
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding Java on macOS
Java is a versatile and widely-used programming language that plays a crucial role in many applications and services. On macOS, managing Java installations and versions is key to maintaining a smooth development process. This article will explore how to view all Java versions installed on your Mac and provide technical details for understanding the macOS Java environment.
Why Multiple Versions?
Java's development lifecycle involves frequent updates and versions. Different projects may require different Java versions due to compatibility with libraries or specific Java features. Therefore, developers often have multiple Java versions installed on their systems.
How to Check Installed Java Versions
Using Terminal Commands
macOS offers a command-line interface known as Terminal, which provides a convenient way to check installed Java versions.
- Check Default Java VersionTo check the default Java version used by your Mac, you can use the
java -versioncommand:
This command will return the version of Java currently set as the default.
- List All Installed Java VersionsTo list all Java versions installed on your Mac, you can execute:
This command outputs details about all Java installations, including version numbers and directory paths.
- Identify Active Java VersionTo determine which Java version is actively being used by a specific application or session, employ the following command:
This command will output the path of the Java executable being utilized.
Sample Output
Here's what the output might look like when executing java_home -V:
Navigating the Output
The output from java_home -V can be a bit verbose, so here's what each part means:
- Version Number: The first part (e.g.,
16,11.0.9,1.8.0_282) indicates the version of Java. - Architecture: The
x86_64specifies the architecture type. - Vendor: This part mentions the vendor providing this Java installation (e.g., "Oracle Corporation," "AdoptOpenJDK").
- Java Installation Type: Specifies if it's the standard edition ("Java SE").
- Installation Path: Finally, the directory path where this Java version is installed on your system.
Managing Java Versions
Setting a Specific Java Version
Sometimes you need to switch the default Java version. This can be done by setting the JAVA_HOME environment variable in your shell configuration file. For example, if using bash, you can add to your .bash_profile:
Replace <version> with the specific version number, such as 11 or 1.8, that matches the installed version you want as the default.
Version Management Tools
Although the java_home utility is the native tool for managing Java versions on macOS, third-party version managers like SDKMAN! provide additional flexibility by allowing you to easily install, switch, and manage various Java versions.
Table Summary
Here is a consolidated table highlighting key commands and operations related to managing Java versions on macOS:
| Command | Function | Example | Output Details |
java -version | Check default Java version | java -version | Shows current default Java version and build |
/usr/libexec/java_home -V | List all installed Java versions | /usr/libexec/java_home -V | Lists all installed Java versions and paths |
which java | Determine active Java path | which java | Outputs the active Java executable path |
export JAVA_HOME=/usr/libexec/java_home -v <version> | Set specific Java version | export JAVA_HOME=/usr/libexec/java_home -v 11 | Sets environment for specific Java version |
Conclusion
Having multiple Java versions on your macOS is not only possible but sometimes necessary for a smooth development workflow. By understanding how to list, verify, and manage these versions, developers can ensure that their applications run with the appropriate Java version, reducing compatibility issues and enhancing project reliability.

