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.
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)
For Windows 7:
Right click on My Computer
Select Properties
Select Advanced System Settings
Select the Advanced tab
Select Environment Variables
Select Path under System Variables
Click on the Edit button
In 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_111. 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...
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:
Search environment variables.
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.
For me its start working after putting ,: in the starting of the system variable path :--
My solution was to put same value (path to JDK bin folder) in JAVA_HOME and Path
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.
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;
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.
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
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\jdk-15.0.2\bin, press OK
I 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`
Like this:
/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?
Close your active terminal;
Open your favorite terminal;
Type 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.
I opened a new command prompt in Windows 10 after updating the environment variables without closing the old one(To have my commands handy and lazy to type again)
Still, the new cmd window was referring to the previous version of Java.
Then once I closed the all cmd prompts that ran with admin privileges, the new java version was getting reflected.
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"
Restart the command prompt before checking the version of JDK installed. I spent 02 days on it until my problem resolved when I restarted the command prompt before checking javac - version, javac etc.
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.
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.
Try this:
System variables:
PATH = /bin folder of your jdk install
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm
Just some extra information for people that have still problems,
instead of editing the path variable of java, delete that part of the path(only the java!!)
and make a new variable pointing tpo the jdk/jre.
this seemed to work for me.
When we set the environment path, can't it work correctly for Java, Eclipse and Android Studio?
How to set it correctly?
When I set it temporarily by using the command prompt, set path is not working correctly.
So I tried to set it permanently by using the environment variable Path, but it's not possible.
How can I set it properly?
Please give me a detailed explanation
Apart from setting the JAVA_HOME system variable you need to set the Path variable as well because the Path is the system variable that your Operating system uses to locate the needed executable from the terminal window.
So for setting the Path Variable proceed as follows:
Right click on the My Computer icon --> Properties -->Advanced system settings --> Environment Variables
Now under System variable scroll to the Path variable
Select Path variable and click on edit button
Now add %JAVA_HOME%\bin in the end of Variable values, separating this value form the existing one in the list with a ;
eg xxxxx;%JAVA_HOME%\bin;
Note that before following the above steps also check if your JAVA_HOME variable is properly set. For doing this go to command prompt and type echo %JAVA_HOME%. If it is properly set then it will give you the path of your jdk.
NOTE: Sometimes it happens that both the Path and JAVA_HOME variables are set properly but still things are not working.To avoid this run the command prompt as administrator.
Android Studio uses JAVA_HOME variable , not Path variable. So You should set up JAVA_HOME Variable.
Right-click the My Computer icon on
your desktop and select Properties
Click the Advanced tab. Click the
Environment Variables button.
Under System Variables, click New.
Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
Note:Normally
installation path is like "C:\Program Files\Java\jdk1.7.0"
I know there are lots of questions and answers about this but none of them are working. I am on a Windows 7 Computer.
I have set my JAVA_HOME in Environment Variables but I keep on getting errors. I have set it to
"C:\Program Files\java\jdkxxx\"
(xxx = Java Version) I have tried setting it without quotes and it still doesn't work.
I get the error
ERROR: JAVA_HOME variable is set to an invalid directory: C:\Program Files\java\java1.7.0_21\ Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
Take out the trailing backslash and remove the quotes
set JAVA_HOME=C:\Program Files\java\java1.7.0_21
1. Navigate to C:/Program Files/Java
Look for any JDK folders and find the last version if you don't have any of them then Download and install from Java official website HERE
2. On your Desktop, right-click on My Computer and open Properties
From the left side choose Advanced system settings
3. At the bottom of the window, press the Environment variables button.
Now we got to add the variable in the both: User and System variable boxes.
4. Click New button at the User variables box and write:
Variable name: JAVA_HOME
Variable value: C:/Progra~1/Java/jdk-folders-name
NOTE: use Progra~1 for Windows x64 and Progra~2 for Windows x32
Then press OK
5. Do the same for the System variables box
6. Press Ok till you close all the windows and run again your Soft.
Or check this video tutorial: https://www.youtube.com/watch?v=47K3gBla76o
I've definitely got JDK 1.6.0 installed in C:\Program Files\Java\jdk1.6.0_35, but it never seems to be able to find it when I try to open the SDK Manager. In task manager, find_java.exe shows up until I stop it (will run for hours).
Are there some environment variables I have to set for this to work?
As you are using Windows system, use following way to set your JAVA_HOME and CLASSPATH Environment variables.
Windows XP
Select Start, select Control Panel. double click System, and select the Advanced tab.
Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Windows Vista:
From the desktop, right click the My Computer icon.
Choose Properties from the context menu.
Click the Advanced tab (Advanced system settings link in Vista).
Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Windows 7:
From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Now in Addition for the Linux Based System following steps used to set JAVA_HOME and CLASSPATH variables,
Open root folder
From the View Menu , ticK "Show Hidden Files" , or press Ctrl + H.
Now you can see a system hidden file called .bashrc
Right click and open it editor, and write following command at the end.
PATH=$PATH:/opt/jdk1.6.0_21/bin
export PATH
JAVA_HOME=/opt/jdk1.6.0_21
export JAVA_HOME
NDK_HOME=/opt/android-ndk-r8
export NDK_HOME
Save and Exit.
May be you are forgetting the PATH environmental variable. To check this use,
In Unix/Linux systems,
echo $PATH
echo $JAVA_HOME
In Windows systems,
echo %PATH%
echo %JAVA_HOME%
If both the tests showed you empty lines, then you may need to set them again.
To set them do this. First try reinstalling java with UAC turned off.
If it failed, do this at the cmd
SetX PATH %PATH%;<path_to_jdk/jre>\bin\
SetX JAVA_HOME <path_to_jdk/jre>
Hope it helps and thinking you are using windows.
I have a book that says to do the following.
Add a JAVA_HOME and ANT_HOME environment variable. - check
Add $JAVA_HOME/bin and $ANT_HOME/bin to my path variable - check
When I then go to the command prompt and try ant -version it says ant is not a recognized command. If I then take the value I plugged into the ANT_HOME variable and use it in place of $ANT_HOME it all works. Is this the way it's supposed to work in windows? I'm not sure so I just figured that whatever was put in ANT_HOME was then parsed in the path variable when used as $ANT_HOME. Thanks.
you can try the following:
SET ANT_HOME=my_path_to_ant_folder
SET JAVA_HOME=my_path_to_jdk_folder
SET PATH=%PATH%;%ANT_HOME%/bin;%JAVA_HOME%\bin;
right click My Computer
click Properties
go to Advanced system settings
click on Advanced tab
click on Environment Variables
click on New...
Now you can define an environment variable, type JAVA_HOME in Variable name and in Variable value the path to you JAVA_HOME, the same thing goes for ANT_HOME.
$ANT_HOME doesn't mean $ANT_HOME, literally. $ANT_HOME means "the value of ANT_HOME".
If Ant is installed at c:\ant, your environment variables should be:
ANT_HOME=c:\ant
PATH = ...;c:\ant\bin;...
Same for JAVA_HOME.
Right click on My computer and select properties.
Click on Advance system settings.
Visit http://codebrizz.blogspot.com.ng/2016/07/installation-and-configuration.html for full configuration guide with images for each step