How to Fix “Java Not Recognized” Error
Here are the three easiest ways to fix Java’s “not recognized as an internal or external command” error:
- Install or reinstall Java and the JDK on your computer
- Add Java’s bin directory to computer’s PATH
- Restart the command prompt, terminal window or Powershell
Is Java installed?
To run the Java command, you must have Java installed.
This may mean that the Java Runtime Environment (JRE) or the full Java Development Kit (JDK) is installed. But to fix the “Java not recognized” error, you must first ensure that Java has been installed.
There are many ways to install Java on Windows or Ubuntu.
Install Java on Ubuntu
To install Java on Ubuntu, a single apt install the order is sufficient.
sudo apt install default-jre Setting up default-jre (2:1.11-72build2) ...
A Java installation on Windows can be done quickly by downloading the Adoptium JDK and running the .msi file with all the default options selected.
Add Java to the PATH
The bin directory of the JDK installation is where the Java executable is located.
If the JDK or JRE’s bin directory is not added to the Windows or Linux PATH variable, programs may not be able to find it at runtime. This would definitely cause the “Java not recognized” error, even if the JDK or JRE is correctly installed.
Restart the terminal window
Terminal window and command prompt only read environment variables on first boot.
If the JDK has been installed and the PATH variable is set correctly, you will still encounter a “Java not recognized” error if PowerShell or the command prompt has not been restarted.
Restart your terminal window or application that needs to find the Java command, then try again. The “Java not recognized” error should be gone for good.
Full text of Java error
The full text of the Java not recognized error is as follows:
C:java-error-fix> java -version 'java' is not recognized as an internal or external command, operable program or batch file.
When Java is installed and configured correctly, this error disappears.