Java is a popular programming language where the code is compiled with the tool named javac. This means if you want to compile your Java code and run it as a binary you should use the javac command or tool. As cross-platform language javac tools are provided for Linux, Windows, and MacOSX. “javac is not recognized as an internal or external command” is an error related to javac too where it can not be found in the specified paths.
Check If Java (JDK) Is Installed
First, we will check if Java or JDK is installed properly. Java Development Kit (JDK) is a tool collection designed to developed, compile, and run Java applications. By default, the JDK and javac are installed into the “C:\Program Files\Java” directory with the jdkX.XX where the X.XX is the version. Navigate to this directory and check if JDK is installed properly.
If you are using 64-bit system the 32 bit JDK may be installed as 32 bit program file located “C:\Program Files (x86)\Java“.
As we can see that JDK is not installed and so the Java directory is not created. Please download the the JDK and install by using the following links.
Check If JAVA_HOME Path Set Properly
The most popular case of the “javac is not recognized as an internal or external command” error is not setting the JAVA_HOME environment variable path or setting the wrong path. Let’s first try to print the JAVA_HOME path value from the command line like below.
As we can see that the %JAVA_HOME% is not set. So we should set the %JAVA_HOME% properly to the JDK binary location. Navigate to the “C:\Program Files” or “C:\Program Files (x86)” and find the “Java\jdkX.XX” folder like below.
We will set the JAVA_HOME environment variable. First, we will open the environment variables via the Start menu typing “environment variable” like below.
In the following screen click to the “Environment Variables” button.
In the following scree there is two type of environment variables. The “System variables” is available system-wide and used by other users. The “User variable for ismail” is only available for the current user. We will put the JAVA_HOME into the System variables so click to “New…” under the system variables.
Put the “JAVA_HOME” to the variable name and “C:\Program Files\Java\jdk-15.0.1\bin” to the Variable value like below and click to the OK.
We can see below that JAVA_HOME path is listed under the System variables.
For more details take a look adding new variable to the environment variables.