Skip to content
java: command not found

java: command not found

DodaTech 2 min read

java: command not found means the Java runtime is not installed or missing from PATH. Without it you cannot run compiled Java programs or JAR files on your system.

What It Means

The java command starts the Java Virtual Machine (JVM) to run compiled bytecode. When the shell returns command not found, it means no JRE or JDK is installed, or the installation is not registered in the PATH environment variable.

Why It Happens

  • No JRE or JDK is installed on the machine.
  • Java was installed but the installer didn’t add it to PATH.
  • The PATH was modified or overwritten after installation.
  • You’re on a minimal container or server image that excludes Java.
  • Multiple Java versions are installed and the symlink is broken.

How to Fix It

1. Check if Java is already on the system

which java
ls -la /usr/bin/java
find / -name java -type f 2>/dev/null

2. Install a JRE / JDK

Ubuntu / Debian:

sudo apt update
sudo apt install default-jre

Fedora / RHEL:

sudo dnf install java-latest-openjdk

macOS (Homebrew):

brew install java

Windows: Download the Oracle JDK installer from oracle.com. During setup, check the box that says “Add to PATH”.

3. Set JAVA_HOME and update PATH

# Find the Java installation directory
dirname $(dirname $(readlink -f $(which javac 2>/dev/null || which java 2>/dev/null)))

# Add to ~/.bashrc or ~/.zshrc
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

4. Verify

java -version
# Expected output:
# openjdk version "17.0.9" 2023-10-17
What's the difference between JRE and JDK?
The JRE (Java Runtime Environment) includes only what you need to run Java programs — the JVM and core libraries. The JDK (Java Development Kit) includes the JRE plus javac, debug tools, and other development utilities. For running programs you only need the JRE.
Why does Java work in one terminal but not another?
PATH is session-specific. If you added export PATH=... to ~/.bashrc but are using zsh, it won’t load. Add the export to the correct shell config file (~/.bashrc, ~/.zshrc, or ~/.profile) for your active shell.
Can I run Java from a portable / USB install?
Yes. Download the JDK archive, extract it to a USB drive, and set JAVA_HOME and PATH to point at the extracted folder’s bin/ directory. This works on any OS without installation.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro