Terminal Java Error:
Error Screenshot:
Reason for the Error:
If you have recently purchased a Mac, or simply formatted your macOS to its factory settings, then by default there is no Java JDK (or JVM) pre-installed on your Mac device.
Hence, when you open the Terminal and run a java or javac command, you will get an error saying this operation couldn’t be completed as the System is unable to locate a Java Runtime.
How to resolve the Error:
- Java 8
- Java 11
- Java 17
- Java 21
- OpenJDK
- Oracle JDK
- AdoptOpenJDK
- Azul Zulu
- Amazon Corretto
- IBM JDK
- SAP Machine
- Red Hat OpenJDK
- Microsoft Build of OpenJDK
- BellSoft Liberica JDK
- GraalVM
- Make sure brew is installed on your Mac. Open Terminal and run the below command to check.
% brew --version zsh: command not found: brewIf you get the above error, instead of version details, follow this article to install brew on your Mac - https://code2care.org/howto/install-homebrew-brew-on-m1-mac
- Now simply run the below commands to install Java 8/11/17,
brew install openjdk@8brew install openjdk@11brew install openjdk@17
To install Amazon Coretto Java JDK
brew install --cask corretto
To install Graal VM Java JDK
brew install --cask graalvm-jdk
To install Oracle Java JDK
brew install --cask oracle-jdk
To install Azul Zulu Java JDK
brew install --cask zulu - Open the web browser and go to : https://aws.amazon.com/corretto
- Now click on "Download Amazon Corretto 17"
- Now, download .pkg file macOS x64 or macOS aarch64 based on your Mac Type.
- Open the "amazon-corretto-17-aarch64-macos-jdk.pkg" file from your downloads folder and complete the installations.
- Open Terminal and you should be able to use Java commands.
To resolve this Java error, you will need to download and install Java JDK or JRE on your Mac.
As of year 2023, you can install Java versions from Java 8 to Java 21 on your device. It is recommended to get a stable LTS (Long Term Supported) version of Java.
List of Java LTS Versions:
Also, depending upon what type of Mac device you have - Intel Based / M1/M2 Max/Ultra you would need a different kind of setup to run Java natively on your device.
Mac Type vs Java installations:
| Mac Chip/Processor Type | Java Compatibility |
|---|---|
| Apple Silicon (M1/M2) | ARM64 (Java 11 and later) |
| Intel | x86 x86_64 (Java 8 and later) |
Finally there is a list of Java distributions to choose from,
Java 8/11/17 Installation Steps
Instead of download the setup from a website, we can easily install Java on your Mac using package manager like Homebrew.
To install OpenJDK Java
Install Java by download DMG Setup file
If for some reasons you are having issues with brew, you can download Java JDK from the internet as well, we will see an example of how to download and install Amazon AWS Corretto JDK version 17 which is a free of cost distribution and requires no login or email.
If you prefer other distributions.
| JDK Distribution | Provider Java download link |
|---|---|
| OpenJDK | https://openjdk.java.net/ |
| Oracle JDK | https://www.oracle.com/java/technologies/javase-downloads.html |
| AdoptOpenJDK (Adoptium) | https://adoptium.net/ |
| Azul Zulu | https://www.azul.com/downloads/zulu/ |
| Amazon Corretto | https://aws.amazon.com/corretto/ |
| IBM JDK | https://developer.ibm.com/languages/java/ |
| SAP Machine | https://github.com/SAP/SapMachine |
| Red Hat OpenJDK | https://developers.redhat.com/products/openjdk/overview |
| Microsoft Build of OpenJDK | https://docs.microsoft.com/en-us/java/openjdk/ |
| BellSoft Liberica JDK | https://bell-sw.com/ |
| GraalVM | https://www.graalvm.org/ |
This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0 and Ventura 13.0.
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!


Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!