'javac' is not recognized as an internal or external command [Solution] (original) (raw)

'javac' is not recognized as an internal or external command, operable program, or batch file error comes when you try to compile a Java source file using the javac command like javac Helloworld.java but your PATH is not set properly. It means that the javac.exe executable file, which exists in the bin directory of the JDK installation folder is not added to the PATH environment variable. You need to add the JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run a Java program until your add Java into your system's PATH variable.

Here is how this error looks like in the command prompt of the windows machine :

'javac' is not recognized as an internal or external command error windows

Steps to fix 'javac' is not recognized as an internal or external command :

Let's see how to fix this problem to compile and run Java program from the command line :

  1. Open command prompt in Windows by clicking the Start button and then typing cmd on the run window, as shown in the following screenshot :

How to open command prompt in windows

  1. Type echo %PATH%, it will now show you all the directories which are available in the PATH environment variable. Now copy this PATH output into your text editor like Notepad or Word-pad and search if it contains the JDK installation directory or JAVA_HOME.

For example, if your JDK is installed on "c:\program files\java\jdk1.8.0", then PATH should include "c:\program files\java\jdk1.8.0\bin". It's important to include bin directory because all executables required to compile, run and debug Java programs are stored in the bin directory.

Sometimes you will also see like %JAVA_HOME%\bin, where JAVA_HOME is another user-defined environment that points to the Java installation directory.

  1. If PATH doesn't contain a bin directory of JDK, then you can add them into PATH by following the command

set PATH = %PATH%;"c:\program files\java\jdk1.8.0\bin

This is also known as setting PATH in Java. Once PATH is set you can compile, run and monitor Java programs by using various tools which comes with JDK installation. If you are not very familiar with setting environment variables from the command prompt, you can also use the settings window as shown in this article.

  1. Don't forget to close the current command prompt and open a new one before running the javac command again. Any change in the environment variable is only available to new cmd windows.

That's all about how to fix 'javac' is not recognized as an internal or external command, operable program or batch file error in Windows. You might get a similar error like 'java' is not recognized as an internal or external command, operable program, or batch file if you try to run an already compiled Java program and PATH is not set in your machine.