When trying to check the current version of Java in which I am running, I received the error "java is not recognized as an internal or external command, operable program or batch file.".
I am running Windows 7 OS and have downloaded the latest JDK and felt I may have accidentally deleted the java from machine as before I was able to check the Java version using the command "java -version".
What software must I download to get Java working on my machine again?
EDIT:
I have managed to get Java running from my cmd again after ensuring all environment variables pointed to the current Java SDK.
This question is related to
java
open the "edit the system environment variables". then click on "environment variables".
Under "User variables" click on "Path" then "Edit".
Find your Java path and click "Edit".
then paste the path of your java installation folder. Mostly you can find it on a path similar to this. C:\Program Files\Java\jdk-12.0.2\bin
Then click OK. now in the start menu, type cmd. open the command prompt. type java -version If you did it right,it should show something like this.
I had the same problem. Just Install the exact bit of java as of your computer. If your PC is 64 bit then install 64 bit java. If it is 32 bit then vice versa :)
Not sure why, but in my case, the reason was because I was running Anaconda terminal instead of the CMD.
After I use CMD and update the path settings as mentioned by all comments above the issue solved on my side.
I corrected my path variable but command prompt need to Restart otherwise, it won't be able to verify the change to the path variable. May be helpful for someone like me. so "restart command prompt"
In my case, PATH was properly SET but PATHEXT has been cleared by me by mistake with .exe extension. That why window can't find java or anything .exe application from command prompt. Hope it can help someone.
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...
This problem is on Windows 8. First copy your Path of java jdk - e.g. C:\Program Files\Java\jdk1.7.0_51\bin.
Right on the My Computer Icon on the Desktop and Click Properties.
Select 'Advanced System Settings' in the left pane.
Under 'Advanced' tab, select 'Environment Variables' at the bottom.
In System Variables, select 'Path' Variable and edit it.
Paste the path and add a ';' at the end - e.g. C:\Program Files\Java\jdk1.7.0_51\bin;
For me its start working after putting ,: in the starting of the system variable path :--
if you have cygwin installed in the Windows Box, or using UNIX Shell then
Issue bash#which java
This will tell you whether java is in your classpath or NOT.
In case you are using a laptop and do not have the Pause\Break button. For windows 10 users with 20h2 and above:
1 WIN ? type "About your PC" ? scroll at the bottom ? Advanced system settings ? Environment variables or WIN+R ? shell:::{bb06c0e4-d293-4f75-8a90-cb05b6477eee}
to open Classic System Properties ? on the left side ? Advanced system settings ? Environment variables
Also for Windows 10 and Windows 7:
1 WIN ? This PC ? properties ? Advanced system settings ? Environment variables
JAVA_HOME
C:\Program Files\Java\jdk-15.0.2\bin
, press OKI have taken steps 2-4 from Vijay Bhatt
There is a bit faster way to set a system variable. Run a console (terminal) as an administrator.
General command synax to add a new variable:
setx variableName value /M
In our example, we would need to set it as
setx JAVA_HOME "C:\Program Files\Java\jdk-15.0.2\bin" /M`
/M
- flag specifies to set the variable in the system environment.
After command execution, you should see the message:
SUCCESS: Specified value was saved.
How can I check that it is added?
java -version
.You should see something similar to this:
Notice:
User variables can be created w/o having a root (administrator privileges), whereas to create System variable
; You need to open a console as a root.
I have used C:\Program Files\Java\jdk-15.0.2\bin
as an example, in your case, it could be different from mine.
If you have set the environment variables (JAVA_HOME
and PATH
) under user variables, command prompt (run as administrator) will not identify java. For that you need to set environment variables under system variables.
My solution was to put same value (path to JDK bin folder) in JAVA_HOME
and Path
For Windows 7:
My Computer
Properties
Advanced System Settings
Advanced
tabEnvironment Variables
Path
under System Variables
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
java -version
in command prompt.Notes on Step 6:
1. 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
Assume, Java/JDK is installed to the folder: C:\Program Files\Java:
Follow the steps:
JAVA_HOME
C:\Program Files\Java\bin
, press OK:
Path
C:\Program Files\Java\bin
, press OK:
cmd.exe
and write: java --version
:
Source: Stackoverflow.com