Terminal Java Error:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
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:
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:
- Java 8
- Java 11
- Java 17
- Java 21
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)|
You can install x86_64 Java Setup on a M1/M2 based ARM Mac, but the performance will not be at optimum.
Finally there is a list of Java distributions to choose from,
- Oracle JDK
- Azul Zulu
- Amazon Corretto
- IBM JDK
- SAP Machine
- Red Hat OpenJDK
- Microsoft Build of OpenJDK
- BellSoft Liberica JDK
Java 8/11/17 Installation Steps
- Make sure brew is installed on your Mac. Open Terminal and run the below command to check.
% brew --version zsh: command not found: brew
If 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@8
Note: There is only x86_64 support for Java 8 so won't work on M1/M2 based Mac.
brew install openjdk@11
brew install openjdk@17
You need not need to worry about the 64/ARM installation, brew will automatically take care of it.
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
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.
- 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.
If you prefer other distributions.
|JDK Distribution||Provider Java download link|
|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/|
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!
Facing issues? Have Questions? Post them here! I am happy to answer!
- Convert Java Map Collection Object to JSON String using Jackson
- Java Stream flatmap() Examples
- [Fix] Instant java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years
- How to run Java Unit Test cases with Apache Maven?
- How to check if Java main thread is alive
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Parsing CSV file using Java code example (Comma Separated File)
- Unhandled exception type InterruptedException : Java Threads
- Native getClass() method from java.lang.Object Class Explained with examples.
- Java Jackson ObjectMapper Class with Examples
- Java 8 Streams map() with examples
- Java 8 - Convert List to Map Examples
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- Java Stream with Multiple Filters Example
- How to Clear StringJoiner in Java 8
- Spring 5 IoC Example with application Context XML (ClassPathXmlApplicationContext) and Gradle.
- How to get end of line (EOL) or new line character \r \n in Java
- Spring Boot CRUD Examples using JDBCTemplate
- Delete a File in Java with Examples
- Implementing Insertion Sort Algorithm in Java Program
- Java JDBC Batch Update Example with PreparedStatement
- Java JDBC Select Multiple Records from table as List using PreparedStatement
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to fix Java HTTP java.net.UnknownHostException
- Java 8 Display time in 12 hour AM PM format
- How to empty trash in Android Device - Android
- Chrome : When Adobe flash player has finished updating, reload this page to active it - Chrome
- How to List all Packages installed using pip [Python] - Python
- Fix: Ubuntu (Linux) - bash: sudo: command not found error - Ubuntu
- Notepad++ Search Across Multiple Lines - NotepadPlusPlus
- Select Line Number TextEdit on Mac - MacOS
- How to Perform Cut/Paste Operations in Nano Editor - Linux