Solve Java Command Not Found Error – ‘java’ is not recognized as an internal or external command

If you’re new to java programming, the error “java command not found” or “’java’ is not recognized as an internal or external command, operable program or batch file” may have occurred to you.

There are 2 reasons that you’re facing “Java command not found” in your Linux/Mac java’ is not recognized as an internal or external command, operable program or batch file” in your windows PC.

Lets discuss these two reasons and its solution one by one.

How to Solve Java Command Not Found Error?

1. JRE is Not Installed in Your System

If you’re facing this error, that means either you’re running a bytecode (.class file) or a .jar file which requires JRE (Java Runtime Environment) to run. So there are two ways to get a Java Runtime Environment. Firstly you have to download and install the JRE, using which you can run the file which requires java.

To Download JRE on windows and MacOS:

https://www.oracle.com/java/technologies/javase-jre8-downloads.html

To Download JRE on Linux (Ubuntu):

Open terminal and execute these commands one by one:

sudo apt update

apt install default-jre

On other hand, if you also want to write programs in java as well as run those programs then you can download and install JDK (Java Development Kit) from https://www.oracle.com/java/technologies/javase-jdk13-downloads.html.

Using JDK, you can develop java programs as well as run those programs. So the JRE comes along with JDK. Which means if you have installed JDK in your system then you won’t be needing to install JRE separately.

To Install JDK in Windows: https://www.thecrazyprogrammer.com/2014/06/java-installation-downloading-installing-and-setting-path.html

Even for the Mac, an installer like Windows is available on the same site.

To Install JDK on Linux (Ubuntu):

Open terminal and execute these commands:

sudo apt update

apt install default-jre

2. The Path of JRE or JDK Has not Been Set

This is one of the most common mistakes we make while installing JRE or JDK in our system. When we install java in our system, it requires a particular location (Example: C:\Program Files\Java\jdk1.8.0_101 ) to extract its files. Now the binary files that we required to run the java file are present in a particular directory. So when you move the file into the bin folder inside the JRE or JDK directory to run it, it will run.

But when you want to run your java file from any directory then you need to paste the path of the bin folder that is inside your JDK or JRE folder to a global path (Environment Variables) from where you can access it anywhere in the system.

To setup the path in windows you can again open:

https://www.thecrazyprogrammer.com/2014/06/java-installation-downloading-installing-and-setting-path.html

To setup the path in Linux (Ubuntu):

You need to open terminal and type:

 sudo gedit ~/.bashrc

It will open .bashrc file in the text editor now go to the last of that file and add following lines:

export JAVA_HOME=/usr/java/<your version of java> export PATH=${PATH}:${JAVA_HOME}/bin

So now you can run your java files without facing the error “java command not found” or ‘java’ is not recognized as an internal or external command, operable program or batch file” in your system.

So that’s all, if you’ve any query or question related to this article, please let us know in comment box.

Leave a Comment

Your email address will not be published. Required fields are marked *