Skip to content
Latchkey

CI "java: command not found" / No JDK on PATH - Fix Setup

The shell could not find a java (or javac) executable on PATH. Either no JDK is installed on the runner, or the JDK exists but its bin is not on PATH.

What this error means

A step calling java/javac/mvn/gradle fails instantly with command not found, before any build work. Common on minimal container images or when the JDK setup step was skipped.

Terminal
./build.sh: line 3: java: command not found
# or
javac: command not found

Common causes

No JDK installed on the runner

A minimal base image ships no Java. Any java/javac invocation fails until a JDK is installed.

JDK installed but not on PATH

The JDK exists under /opt or /usr/lib/jvm but its bin was never added to PATH (and JAVA_HOME is unset), so the shell cannot find it.

How to fix it

Set up a JDK

Provision a JDK and put it on PATH. setup-java handles both.

.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: temurin
    java-version: '21'
- run: java -version

Install a JDK in a container image

On a bare container, install the JDK package or use a JDK base image.

Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y openjdk-21-jdk
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"

How to prevent it

  • Use actions/setup-java (or a JDK base image) so Java is always present and on PATH.
  • Set and export JAVA_HOME explicitly in container builds.
  • Add a java -version assertion early in the job.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →