How to resolve javac is not recognized as an internal or external command in java?

When you compile a program if you see this error it indicates that either you have not installed Java in your system properly or, you haven’t set the Path variable.

The Path variable − The path environment variable is used to specify the set of directories which contains executional programs.

When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it.

In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.

Setting Up the Path for Windows

Assuming you have installed Java in c:\Program Files\java\jdk directory −

  • Right-click on 'My Computer' and select 'Properties'.
  • Click the 'Environment variables' button under the 'Advanced' tab.
  • Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.>

Setting Up the Path for Linux, UNIX, Solaris, FreeBSD

Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation, if you have trouble doing this.

Example, if you use bash as your shell, then you would add the following line to the end of your '.bashrc: export PATH = /path/to/java:$PATH'