In this tutorial I will show you how to set JAVA_HOME as environment variable in Windows 10 operating system.
Why do I need to set JAVA_HOME?
Many Java based programs like Tomcat require JAVA_HOME to be set as environment variable to work correctly. Please note JAVA_HOME should point to a JDK directory not a JRE one. The point of setting the environment variable is to let programs know in which directory executables like javac can be found.
1. Open Advanced System Settings
In Windows 10 press Windows key + Pause Key, This will open the System Settings window. Go to Change settings
and select the Advanced
tab.
Alternatively:
Open “Windows search” – you will find it next to the Windows logo
1. In the search field type in – advanced system settings
2. Click on the match on top of the list
The service for java script on the website selling generic medicines online is very well implemented.
2. Set JAVA_HOME Environment variable
In “System Properties window” click “Environment Variables…”
Under “System variables” click the “New…” button and enter JAVA_HOME as “Variable name” and the path to your Java JDK directory under “Variable value”
3. Update System PATH
1. In “Environment Variables” window under “System variables” select Path
2. Click on “Edit…”
3. In “Edit environment variable” window click “New”
4. Type in %JAVA_HOME%\bin
4. Test your configuration
Open a new command prompt and type in:
echo %JAVA_HOME%
this will print out the directory JAVA_HOME points to or empty line if the environment variable is not set correctly
Now type in:
javac -version
this will print out the version of the java compiler if the Path variable is set correctly or “javac is not recognized as an internal or external command…” otherwise. UPDATE: in the comments below there are several suggesting to run the command prompt as administrator if you see the error message. Please make sure you try this option
Nice Explanation. working fine for me.
Thank you!!!! I have been at this for an hour. Out of all the suggestions yours is the only on that worked.
Hi! Thank you for the explanation, it works well. However I have the following problems: (java -version and javac -version works fine) I am working from the command line. I want to compile a specific class, so I type the following: cd C:\Users\tothn\Java\Projects\SetUpPractice\src\HelloOTP //this directory contains the .java file javac HellOTP.java //now the HellOTP.java compiles perfectly. a new file, HellOTP.class appears when I type: C:\Users\tothn\Java\Projects\SetUpPractice\src\HelloOTP\java HellOTP It displays the message: Error: Could not find or load main class HellOTP.java The file works from an IDE (Netbeans), but I want to run it from cmd… My Classpath variable is set to… Read more »
You need to run the java command with your class:
C:\Users\tothn\Java\Projects\SetUpPractice\src\HelloOTP\java HellOTP
will not work, try this 2 commands instead:
cd C:\Users\tothn\Java\Projects\SetUpPractice\src\HelloOTP
java HellOTP
Thank you for the clear instructions! Help a lot.
I can only find the JRE directory on my Windows 10 computer. Where might I find the JDK directory?
Please first make sure you have downloaded and installed the JDK (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) NOT the JRE (http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
If you stick with the default folder during the installation, Java JDK is located at C:\Program Files\Java\jdk1.8.0_xxx
Thanks very much for the detailed explanantion
Thank you it is worked. and your facebook login authentication app is not working. i mean that CONNECT WITH facebook button above the comment section. 🙂
thank you so much.
Doesn’t work
echo %JAVA_HOME%
%JAVA_HOME%
Looks like your in Powershell; type: $env:JAVA_HOME
CommandPrompt is NOT PowerShell
Oh my i was doing the same mistake for 1 hours and i was trying to figure out what its wrong! Thank god that i found your comment here!
Good explanations – does not work. Tried various things, out of options. Test #1 – echo %JAVA_HOME% – produces:
C:\Users\Owner>echo %JAVA_HOME%
c:\program files (x86)\java\jdk1.8.0_74
Test #2 fails, returning:
C:\Users\Owner>javac -version
‘javac’ is not recognized as an internal or external command,
operable program or batch file.
For test #2 I have tried both the Program Files and the Program Files (x86) folders. Can’t see where I am going wrong… Windows 10 PC. Freshly downloaded as of today.
Hi Jon,
Please look again at point 3 of this tutorial.
To be able to call javac the way you try it, you need to add %JAVA_HOME%\bin in your System Path. Note that javac.exe and java.exe are in the “bin” subfolder.
Hi filip, Can it be a permissions issue? I double-checked my entries as you directed. They are fine. Here’s the odd thing. When I do test 1 above, it responds with the location of the bin sub-folder. When I do a search for it Windows says it can’t find it. Here is where test #1 says it is: c:\program files (x86)\java\jdk1.8.0_74 I can’t see it in Windows Explorer and I tried setting WE to display hidden and system files and that did not display it. I can be a pretty logical person but this doesn’t seem to make sense. Thinking… Read more »
I have the same issue. Instead of using javac just use java and see what you get. It shows me a printout of the build number so I think that’s what the expected result is.
Ok Scratch my previous reply to this. I found my problem which seemed to be the same as your problem with some trial and error and some of the responses here. First, I had downloaded JRE instead of SDK so if that is the problem, uninstall JRE then install SDK which includes a version of JRE with more features. Second, when you add the variable path make sure it points at the SDK folder instead of the new JRE folder. Both contain a home and a bin folder so that should fix any variable problems. Finally, when I try the… Read more »
Thank you it helped
Hi Jon, When you run the command prompt you need to run it as a System Adminstrator. I had the same problem as you until I did this. Your mention of “permissions issue” is what helped me work it out.
That was a critical error in the instructions. Once I ran the System Admin Powershell, it worked. Thank you.
Lester, you help me. But I don’t know why the javac worked only in System Admin Powershell. Thanks…
Thanks! Nick
I have the same problem even after adding %JAVA_HOME%bin to the system path as described.
Hey good Job, worked out smooth
thank you
thank you sir/madam
echo %JAVA_HOME% command is giving the correct output but javac -version is printing javac is not recognized as an internal or external command. anyone can help?
Hi Dalvir, try to move your %JAVA_HOME%\bin configuration to the top of “System Variables – Path”.
akd, thank for the help. My javac only work when I moved it for top of the variables.
Yes doing this works now, thanks!
Hey..thanks, moving the configuration to the top in the Path worked for me!
It is worth noting that if you do not find the JDK in program files to look for it in program(86)/java instead of program/java
if second step did not work for you try to add \ at the end of the %JAVA_HOME%\bin and make it %JAVA_HOME%\bin\
I typed in System Path ‘C:Program FilesJavajdk-10.0.2bin’ instead ‘%JAVA_HOME%bin’ and it worked!
Danke schön
fixed. THANKS BRO!
Excellent, Thank you very much!, works for me!
Thanks alot for your easy guidence
very very good
Works fine for me. Big thanks!
Thank you guys…
thank you
Some of Tuts are always hides the primary information But this one nailed! Hats off. 🙂
Thank you!
Thank you very much… this post was the only post that helps me with Java and Win10. Thank you
here test configuration cmd command is — java -version
Could you please correct that one.
It is useful to people thanks for providing.
Thanks for your help!
I still get the error that “‘javac’ is not recognized as an internal or external command,
operable program or batch file.”
The correct syntax for getting java version changed – just type ‘java -version’ (not ‘javac -version) if you have the correct pathing JAVA_HOME already established.
Thank you Chas
Hi, Thank you for the instruction which I rate as the best. However, by following the instruction, I added JAVA_HOME as a new system variable name and put C:\Program Files\Java\jdk1.8.0_201 as its value. Then edit PATH and add %JAVA_HOME%\bin as a new path. Then in command prompt I typed echo %JAVA_HOME% . It shows only %JAVA_HOME% instead of the real path. Please kindly help. Thanks!
Now my Android studio is downloading. I think the problem is solved.
It worked and solved my problem. Thankyou
Finally. Idiot proof step by step how to solve this. Exactly what I need 🙂
nice one. 100% working
I have tried my best to follow the instructions here. After several hours trying to set this up, I am going to uninstall Java. Even Mozilla no longer supports it. I wanted to use Libre Office and especially I wanted to use Data Crow, but the info provided by Oracle is incomplete or they assume we are all computer genius.
Just open cmd as administrator, type c:\set PATH=%PATH%;C:\Program Files\Java\jdk-12\bin
Assuming you are using java development kit 12.
I don’t have a Jdk directory, only Jre. What can I do ?
You’ll need to do a few things.
First, download and install the JDK.
Remove the JRE from the PATH
Add the JAVA_HOME variable in.
Then you can start using the JDK!
Here’s supplementary article I put together just on JAVA_HOME:
https://www.theserverside.com/feature/How-to-set-JAVA_HOME-in-Windows-and-echo-the-result
And here’s an explanation of the JAVA_HOME error you were seeing:
https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-fix-common-JAVA_HOME-errors-quickly
Happy Java!
If none of these work for you then do this below method It will sure work for you…
Add JAVA_HOME In the SYSTEM variable instead of user variable
Step-1
:Go to ENVIRONMENT >system variable> Click on NEW > add JAVA_HOME and its Path
Step-2
System variable>path>edit>New> then add this %JAVA_HOME%\bin ****** no need to add ” \” [forward slash] after bin ************** This will definitely work for you
really nice lub u lot
Thanks, Very clear and simple way presented.
Thank You, It was very helpful
Easy to follow. Clear explanation.
javac -version is not recognized the rest echo %JAVA_HOME% worked.
I personally feel that this article is not written properly . Several times , I read the instructions written here and followed and then tried to execute , but , not a single time I got the desired result which was to have jdk run properly.The command prompt was not showing javac as any recognised command after following each of the step correctly . Finally , I saw a video on this on “edureka” channel on youtube, followed the given instructions nd got the results . I got the relief then. So , I personally feel that you should add… Read more »
Can you share the link of that video so that we too can work on Java properly and quickly.
thank you very much
cmd needs to be opened as administrator otherwise it will not show JAVA_HOME path
Thank you, works perfectly fine.
Need help to set system path
Thanks .. Dear … so simple and accurate
Thank you for the clear instructions!