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
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
More Posts related to MacOS,
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- Zsh Shell: Custom alias that you may find useful
- How to switch from bash to zsh shell in macOS Terminal
- [Solution] macOS could not be installed on your computer OSInstall.mpkg appears to be missing or damaged
- Add Bookmark macOS Safari
- How to install Java on macOS [Big Sur]
- Move from Zsh to Bash shell macOS
- WARNING: Python 2.7 is not recommended [macOS Big Sur]
- This operation couldnt be completed. Unable to locate a Java Runtime. [macOS]
- How to do calculations in Mac Terminal
More Posts:
- Force android app to run in Landscape mode programatically - Android
- Type R is already defined error : Android Error - Android
- Call PHP function on Button click using jquery ajax - PHP
- Can't Run SDK Manager find_java.bat issue - Android
- 10 FTP SFTP Clients and Alternatives - FTP
- auth_client_using_bad_version_title : Error Android Lint - Android
- Delete file using PHP code : unlink() - PHP
- Stop android adb service from command prompt or terminal - Android
- How to add Date and Time to Windows Notepad File - NotepadPlusPlus
- Mac OS X Taking Screen Capture using Terminal - Mac-OS-X
- Create SharePoint Site Collection using PowerShell New-SPSite - SharePoint
- SharePoint workflow Canceled - Coercion Failed: Unable to transform the input lookup data into the requested type - SharePoint
- Android : Prevent App for rotation landscape or portrait - Android
- MySQL 1005 Error : SQLSTATE: HY000 (ER_CANT_CREATE_TABLE) Message: Can't create table '%s' (errno: 150) - MySQL
- How to change Android EditText Cursor Color - Android