# macOS: The operation couldn't be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java

**Code:** `Unable to locate a Java Runtime` · **Category:** macOS · **Seen on:** macOS, Java

macOS has no JDK installed (or the installed one isn't registered), so the `java` stub fails.

## Meaning

Install a JDK (`brew install openjdk@21` or Temurin) and link it: `sudo ln -sfn $(brew --prefix openjdk@21)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk`. Set `JAVA_HOME` with `/usr/libexec/java_home -v 21`. `/usr/bin/java` is only a stub that finds JDKs under `/Library/Java/JavaVirtualMachines`.

## Common causes

- No JDK installed
- Homebrew OpenJDK not symlinked into JavaVirtualMachines
- JAVA_HOME pointing to a removed JDK
- Wrong architecture JDK
- PATH missing brew openjdk

## Quick fix

1. `brew install --cask temurin` or `brew install openjdk@21` + the symlink
2. `export JAVA_HOME=$(/usr/libexec/java_home -v 21)`
3. Verify: `java -version`

## Detailed fix by platform

### macOS

1. `/usr/libexec/java_home -V` lists registered JDKs

## How to diagnose

1. **JDK** — Installed?
2. **Registered** — java_home lists it?
3. **JAVA_HOME** — Valid?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/macos/java-runtime-not-found)
