'javac' is not recognized as an internal or external command [Solution]

'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


2) 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. 



3) 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.

4) 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.

61 comments:

  1. Hey Guys,
    Even I was having the same issue and I did following 2 things which finally worked for me:
    1. In system variables (in Advanced tab) created a new variable 'CLASSPATH' with value 'C:\Program Files\Java\jre-10\lib'
    2. Closed current cmd prompt window (as it was still giving the same error), opened new cmd window where I got correct response for javac :)
    Hope it helps.

    ReplyDelete
    Replies
    1. Thanks, it was "the" exact case.

      Delete
    2. Thank You, It worked for me

      Delete
    3. finally thank you

      Delete
    4. still broken...

      Is it because one of my other programs had a variable called path? Anyway I removed that program but its still busted.

      Delete
    5. just install jdk 8. can't run programs at jdk 9 up

      Delete
    6. Thanks it works for me using two steps you mention.

      Delete
    7. Yash Jagtap , Thanks

      Delete
    8. Thanks a lot, this worked for me

      Delete
  2. Thanks, Its Working

    ReplyDelete
  3. I use this very steps and used to work.. But now its not working..
    What to do? Plzz help

    ReplyDelete
    Replies
    1. Hello Unknown, can you please provide more details, what are you trying to do, what is your system, what is in your PATH environment variable etc?

      Delete
    2. the version might have changed...

      Delete
  4. Working by setting c:\program files\java\jdk1.8.0\bin as 'path' in user variables(Y)

    ReplyDelete
  5. Thanks. Its working for me by setting c:\program files\java\jdk1.8.0\bin as 'PATH' in user variables(Y).

    ReplyDelete
  6. Replies
    1. Can you please provide some more details? what error you are getting, what is in your PATH and CLASSPATH? What have you tried so far? This will help me to understand the issue better and help you faster.

      Delete
    2. Tried path, tried class path and path.
      Path = C:\Program Files\Java\jdk-12.0.1\bin

      Windows 7 64 bit operation system.
      I have installed java 5 times now, 0 have worked. Followed 5 completely different tutorials, 0 worked.

      Error is javac is not recognized as internal or external command program batch file.html (read the title...)

      Does it have to be called PATH or CLASS PATH or what.

      I recently had a broken called brakets that had a path file so I deleted it, probably makes no effect I don't know.

      My PC isn't very good, does that make a different. I don't know, it can run other things, e.g. unity.

      Is that enough info?

      Delete
    3. can you open a command prompt and run the echo %PATH% for me and print the output here?

      Delete
    4. C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\bose-3\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools\;C:\Android;C:\Windows\System32;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\nodejs\;C:\Program Files (x86)\WebEx\Productivity Tools;C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools\Best Practices Analyzer\;C:\Program Files (x86)\Webex\Webex\Applications;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Java\jre1.8.0_161\bin

      Delete
  7. 0001011110111101111111011011101011110111111110001010101011111110010101000101000010101010101010101010101010101000101111110101010001000111010101010101010101010101010100000000000000000001111010101011010111010101010101010110

    ReplyDelete
  8. When the file is placed at bin location, there is no error in compilation. But when I tried to compile the file at desktop location, I'm facing issues. Can you help me?

    ReplyDelete
    Replies
    1. check if your PATH has desktop in it, I think it has bin folder but not Desktop.

      Delete
    2. Thanks... Now it's working fine...

      Delete
  9. I did the same thing but it is showing like that can any one help me

    ReplyDelete
  10. C:\Program Files\Java\jdk-12.0.2\bin
    im getting error msg 'Hello.java' is not recognized as an internal or external command,
    operable program or batch file.

    ReplyDelete
  11. Dear vib,
    Kindly check if the directory in which you have saved your program and directory of cmd is same or not.

    ReplyDelete
  12. getting an error as "could not find or load the main class 'class_name'" when i execute the java command

    ReplyDelete
  13. its not working for me i have tried almost all what everyone has said...can anyone helpme

    ReplyDelete
  14. not working tried the all steps as listed above
    plz help me

    ReplyDelete
    Replies
    1. plz verify that what your system has actua or current l link for java to verify this press Win+R key to open run command then type cmd, in cmd type the following code, eco %PATH% cmd will show your actual path which is system currently assuming, if it shows different then C:\program file\java\jdk-12.0.1\bin so go back to system veriable then delete the path which cmd shows and create new in user veriable section give name "Path" and paste the bin directry path press ok and then close all opened cmd, niw open new cmd and type javac and hit enter, boom it will work

      Delete
  15. C:\Users\Ionut>%path%
    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file.

    what have i done?

    ReplyDelete
  16. Resolved it by adding JAVA_HOMEC:\Program Files\Java\jdk1.8.0_181

    ReplyDelete
  17. Resolved it by adding environment variables JAVA_HOME - C:\Program Files\Java\jdk1.8.0_181

    ReplyDelete
  18. I have set the path in environment and also java_home. but i cannot make cmd to find java file.
    error everytime file not found. it sucked now for me. i have re-install and all casual checkings. trying java 13

    Need help with this..

    ReplyDelete
    Replies
    1. Which OS are you trying? If you are in Windows, can you print echo %PATH% on command prompt? if you don't see JAVA_HOME, then just add the full path like C:\\java\bin in your path by using set PATH = %PATH%;C:\java\bin etc and try

      Delete
  19. under echo %PATH% it didnt show C:\Program Files\Java\jdk-13.0.1\bin .... so i use PATH = %PATH%;C:\Program Files\Java\jdk-13.0.1\bin and when i type echo %PATH% it show it on the list but when i restart cmd it disappear again.. and im getting same problem

    ReplyDelete
  20. Resolved by editing system environment variables and adding this path: => C:\Program Files\Java\jdk-13.0.1\bin

    ReplyDelete
  21. Thanks it helped MINE set PATH = %PATH%;"c:\program files\java\jdk1.8.0\bin

    ReplyDelete

  22. Hello Guys:

    I need some help in running my code on windows pshell and cmd. Compiler is working fine. However I am not able to run it.

    PS D:\JAVA_NOTEPAD> java .\Dice.java
    Error: Could not find or load main class .\Dice.java
    PS D:\JAVA_NOTEPAD>

    C:\WINDOWS\system32>echo %PATH%
    C:\Program Files\Java\jdk1.8.0_231\bin;C:\Users\Gurjap Singh\AppData\Local\Microsoft\WindowsApps

    C:\WINDOWS\system32>echo %CLASS_PATH%
    C:\Program Files\Java\jre1.8.0_231\lib

    C:\WINDOWS\system32>

    ReplyDelete
  23. Replies
    1. Thanks @Tech, happy that you find this tutorial useful.

      Delete
  24. Mine won't work still.

    C:\Users\Ultim\Desktop\Example>javac HelloWorl.java
    'javac' is not recognized as an internal or external command,
    operable program or batch file.

    java version "1.8.0_241"
    Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
    Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)

    C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Oculus\Support\oculus-runtime;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NGX;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Java\jre1.8.0_241\bin;C:\Users\Ultim\Desktop\Example;C:\Users\Ultim\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Java\jre1.8.0_241\bin;C:\Users\Ultim\Desktop\Example;

    ReplyDelete
  25. The last point was also very important, dont forget to close and reopen the command prompt or else you will not see the changes.

    ReplyDelete
  26. I ran echo %path% and even though the correct location showed up, javac still is not recognized.
    C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Users\franc\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Java\bin;

    ReplyDelete
    Replies
    1. Where is your javac.exe is located? I can see C:\Program Files\Java\bin but I doubt you have javac there, you can go and check in that folder first, It looks like JRE than JDK, Javac is usually find in JDK/bin folder

      Delete
  27. Actually in the beginning I got this problem, then somehow I sorted it out by setting path properly. Now once again I got this problem, what I can do now.

    ReplyDelete
  28. IF you are using a workspace or machine which is managed by your company and you can't access system setting to change the PATH then also you can change PATH for your account. Just type "env" on run command window on Windows 7 or Windows 10 and use the change env settings for your user account, there you can define PATH, JAVA_HOME, etc to add any binary including Java to your PATH.

    ReplyDelete
  29. where is the settings window as shown in this article? on step 4..?

    ReplyDelete
    Replies
    1. you mean command line window? Just click the windows on your laptop and it will open run window, type "cmd" there it will open command prompt where you can see the value of PATH variable and also add new directory or executable in PATH using "set PATH" command.

      Delete
  30. Hi, looking for a bit of help. I have downloaded JDK and have set my system environmental path to include the correct path. Here is the echo path root.

    C:\Users\reid1>echo %PATH%
    C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;"C:\Program Files\Java\jdk-15.0.2\bin;";C:\Users\reid1\AppData\Local\Microsoft\WindowsApps;"C:\Program Files\Java\jdk-15.0.2\bin;";

    Any help would be appreictaed as to why it is not working.

    ReplyDelete
    Replies
    1. how did you set your path? and what error are you getting in command prompt?

      Delete
  31. Tried everything but it is still showing javac not recognised

    ReplyDelete
  32. The problem was solved to me when a used the javac path that the android studio already had, so the path was sometgin like C:\Program Files\Android\Android Studio\jre\bin.

    To me, worked, hope that it helps someone.

    ReplyDelete

Feel free to comment, ask questions if you have any doubt.