This operation couldnt be completed. Unable to locate a Java Runtime. [macOS]


If you purchased a new Mac device (Macbook, iMac, Mac mini) and trying to run java or javac command in Terminal you will get the below error as there is no Java Runtime pre-installed.

code2care@mac ~ % java
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

code2care@mac ~ % javac
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Unable to locate Java Runtime macOS Error
Unable to locate Java Runtime macOS Error

You need to visit http://www.java.com and download java dmg setup and install.

Note: Native M1 Oracle Java is not yet available for MacBooks/Mac Mini's that are running on Apple Silicon M1 Chips, this setup will work using Rosetta 2 - which will convert the code for you!
Intel-based Mac running Mac OS X 10.7.3 (Lion) or later.

Update: You can install Open JDK that natively supports M1 Mac's : https://code2care.org/q/install-native-java-jdk-jre-on-apple-silicon-m1-mac




Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.