'Java' is not recognized as an internal or external command
Assume, Java/JDK is installed to the folder: C:\Program Files\Java:
Follow the steps:
- Goto Control Panel → System → Advanced system settings → Advanced → Environment variables (Win+Pause/Break for System in Control Panel)
- In the System variables section click on New…
- In Variable name write:
JAVA_HOME
- In Variable value write:
C:\Program Files\Java\bin
, press OK: - In the System variables section double click on
Path
- Press New and write
C:\Program Files\Java\bin
, press OK: - In Environment variables window press OK
- Restart/Run
cmd.exe
and write:java --version
:
For Windows 7:
Right click on
My Computer
Select
Properties
Select
Advanced System Settings
Select the
Advanced
tabSelect
Environment Variables
Select
Path
underSystem Variables
Click on the
Edit
buttonIn Variable value editor paste this at the start of the line
C:\Program Files\Java\jdk1.7.0_72\bin;
Click Ok then Ok again
Restart command prompt otherwise it won't see the change to the path variable
Type
java -version
in the command prompt.
Notes on Step 8:
- The version of java in this may be different from the one used here -- this is only an example.
- There will probably be other values in the path variable. It is really important that you don't delete what's already there. That's why the instructions say to paste the given value at the start of the line -- this means that you don't remove the existing value, you just put java before it. This also fixes any problems you'd be getting if an other version of java is also on the path.
Notes on Step 6:
- This sets the path for the computer, not for the individual user. It may be that you're working on a computer which other developers also use, in which case you'd rather set the user variables, rather than the system variables
It sounds like you haven't added the right directory to your path.
First find out which directory you've installed Java in. For example, on my box it's in C:\Program Files\java\jdk1.7.0_11
1. Once you've found it, try running it directly. For example:
c:\> "c:\Program Files\java\jdk1.7.0_11\bin\java" -version
Once you've definitely got the right version, add the bin
directory to your PATH
environment variable.
Note that you don't need a JAVA_HOME
environment variable, and haven't for some time. Some tools may use it - and if you're using one of those, then sure, set it - but if you're just using (say) Eclipse and the command-line java
/javac
tools, you're fine without it.
1 Yes, this has reminded me that I need to update...
You need to configure your environment variables, JAVA_HOME
and PATH
.
JAVA_HOME
must contain the path to java, and you should add %JAVA_HOME%\bin to PATH
Alternatively, you can simply add to your PATH
the whole path to the bin folder, without the JAVA_HOME
variable, however, this makes a little more annoying when you need to have more than one java version on your machine (that way you only need to change JAVA_HOME
and don't even bother with PATH
)