Environment Variable errors - not recognized as an internal or external command

19,522

Solution 1

Windows console need to be restarted to apply changes made in environment variables

Solution 2

That output means the the environment variable is not set. You can do this in the console with:

set variable=value

Or better go to your system settings and set them permanently. See also this site how to set them.

Solution 3

JAVA_HOME is the environmental variable that java uses. you know you have it right when you type java -version and get what you expect (1.7.x). the PATH variable just allows you to type in a binary name (that's found on the PATH) without prefixing it with the path-to-the-binary/binary.

Share:
19,522
Matt Stevens
Author by

Matt Stevens

Doing a Software Engineering Masters at Victoria, here in Wellington NZ. Am picking up stuff all the time.

Updated on June 05, 2022

Comments

  • Matt Stevens
    Matt Stevens almost 2 years

    This is a rewrite to consolidate what I have picked up searching for answers to resolve my problem. I had installed Ant. When I used "ant" on the Command Line, I got the message "ant is not recognized as an internal or external command, operable program or batch file." I quickly established this was a problem with my Environmental Variables.

    I am assuming you have already got instruction on changing your Environmental Variables. The bullet points below cover the finicky bits, the assumed knowledge, that those writing instructions do not tell you. I suggest just stepping through them when trying to resolve this.

    It will be important to know I am running Windows7. These points are likely fairly universal for Windows, but I leave that for the reader to establish.

    If your issue is still not resolved, please create a new question, perhaps referring back to this one. Do not ask for help on this question as it has been resolved. Other solutions found though can be added here (or posted & I will add them).

    You have solved the Environmental Variable problem once you can get a version number from the Command Line (eg: "ant -version" or "java -version"). After that, you have a different problem. I spent an extra 2 hours trying to 'fix' a "Buildfile: build.xml does not exist! Build failed" Command Line error, not realising that meant this problem was fixed and I had moved onto another one.

    One last piece of advice. Copy and paste your entire PATH variable to somewhere safe while you are playing with it. If you accidentally hit "Delete", you do not get an opportunity to recover and that could lead to a lot of pain.

    Step through these;

    • close all open Command Line Consoles (Windows Consoles) and restart it. This will reset the variables and needs to be done this every time you make a change to the Environmental Variables.
    • ensure you have left no white spaces in the Environmental variables. No space at the end and no space between variables.
    • check your spelling is consistent and check your locations are correct.
    • add your new text to the start of the PATH variable, not the end. This avoids conflicts with other stuff and any issues if you have added it more than once. It stops reading on the first success.
    • ensure the PATH variable has a semi-colon (";") inserted between your new addition and the existing text (no white spaces).

    If Command Line "echo %JAVA_HOME%" returns "%JAVA_HOME%", then you possibly have a permissions issue (use your %variable% not my %JAVA_HOME%);

    • put the new variable (eg "JAVA_HOME" or "ANT_HOME") and its path, into the System Variables. Delete it from the User Variables.

    Using User variables was the last problem I had to fix. Bizarrely "echo %JAVA_HOME%" was fine, but "echo %ANT_HOME%" returned "%ANT_HOME%".

    Finally, if all else fails;

    • restart your computer
    • get new copies of your software, install and restart.

    My thanks to those that helped & the previous Stack Overflow authors whose posts I read trying to find solutions.