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
View Comments (103)
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 "." the currend dir....
What is the problem, can you help?
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 I am missing a piece of the puzzle...
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 basic code in my beginner tutorial it always thrown an error unless I first map to the folder to run the code from so it has the user then my name then > you just add the comman CD then a space and the path. To make it simple I usually just go to my CD/ which goes to the C drive then I do CD and the path. Then I run the javac command. Hope this helps.
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.