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/null2. Install a JRE / JDK
Ubuntu / Debian:
sudo apt update
sudo apt install default-jreFedora / RHEL:
sudo dnf install java-latest-openjdkmacOS (Homebrew):
brew install javaWindows: 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:$PATH4. Verify
java -version
# Expected output:
# openjdk version "17.0.9" 2023-10-17Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro