How to set JAVA_HOME in Windows 10

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

open Windows10 search

open Windows 10 search


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.


Search for advanced system settings

Search for advanced system settings in Windows 10




2. Set JAVA_HOME Environment variable

In “System Properties window” click “Environment Variables…”

system properties window environment variables

system properties window 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”

Add JAVA_HOME as system variable

Add JAVA_HOME as system variable

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

Update system path

Update system path

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

Test JAVA_HOME and system path

Test JAVA_HOME and system path

4.9 61 votes
Article Rating
guest
73 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
vanitha
vanitha
2 years ago

Nice Explanation. working fine for me.

Taneisha
Taneisha
2 years ago

Thank you!!!! I have been at this for an hour. Out of all the suggestions yours is the only on that worked.

gravis ultrasound
gravis ultrasound
2 years ago

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 »

eli
eli
2 years ago

Thank you for the clear instructions! Help a lot.

Matt
Matt
2 years ago

I can only find the JRE directory on my Windows 10 computer. Where might I find the JDK directory?

Mayowa Olunuga
Mayowa Olunuga
2 years ago

Thanks very much for the detailed explanantion

Sahan Pasindu
Sahan Pasindu
2 years ago

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. 🙂

Hung vu
Hung vu
2 years ago

thank you so much.

Sefer
Sefer
2 years ago

Doesn’t work

echo %JAVA_HOME%
%JAVA_HOME%

Marco
Marco
1 year ago
Reply to  Sefer

Looks like your in Powershell; type: $env:JAVA_HOME
CommandPrompt is NOT PowerShell

Jon Kreski
Jon Kreski
2 years ago

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.

Jon Kreski
Jon Kreski
2 years ago
Reply to  filip

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 »

Kyle
Kyle
2 years ago
Reply to  Jon Kreski

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.

Kyle
Kyle
2 years ago
Reply to  Jon Kreski

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 »

Nick Hartley
Nick Hartley
2 years ago
Reply to  Jon Kreski

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.

Lester Flax
Lester Flax
1 year ago
Reply to  Nick Hartley

That was a critical error in the instructions. Once I ran the System Admin Powershell, it worked. Thank you.

Dinesh
Dinesh
2 months ago
Reply to  Nick Hartley

Thanks! Nick

Lester Flax
Lester Flax
1 year ago
Reply to  Jon Kreski

I have the same problem even after adding %JAVA_HOME%bin to the system path as described.

ulliu
ulliu
2 years ago

Hey good Job, worked out smooth
thank you

susovan
susovan
2 years ago

thank you sir/madam

dalvir kaur
dalvir kaur
2 years ago

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?

akd
akd
1 year ago
Reply to  dalvir kaur

Hi Dalvir, try to move your %JAVA_HOME%\bin configuration to the top of “System Variables – Path”.

Jeremy
Jeremy
2 years ago

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

Titan
Titan
2 years ago

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\

Yaraslau
Yaraslau
2 years ago

I typed in System Path ‘C:Program FilesJavajdk-10.0.2bin’ instead ‘%JAVA_HOME%bin’ and it worked!

Ss41
Ss41
2 years ago

Danke schön

Zachary Gancarz
Zachary Gancarz
2 years ago

fixed. THANKS BRO!

AlejoX
AlejoX
1 year ago

Excellent, Thank you very much!, works for me!

Bluck Paul
Bluck Paul
1 year ago

Thanks alot for your easy guidence

morteza
morteza
1 year ago

very very good

alkobarier1rub
alkobarier1rub
1 year ago

Works fine for me. Big thanks!

anonymous
anonymous
1 year ago

Thank you guys…

gautam
gautam
1 year ago

thank you

1 year ago

Some of Tuts are always hides the primary information But this one nailed! Hats off. 🙂

Nancy
Nancy
1 year ago

Thank you!

RonnyDee
1 year ago

Thank you very much… this post was the only post that helps me with Java and Win10. Thank you

vidy
vidy
1 year ago

here test configuration cmd command is — java -version
Could you please correct that one.
It is useful to people thanks for providing.

Michael J
Michael J
1 year ago

Thanks for your help!

Lester Flax
Lester Flax
1 year ago

I still get the error that “‘javac’ is not recognized as an internal or external command,
operable program or batch file.”

Chas
Chas
1 year ago
Reply to  Lester Flax

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.

Dien
Dien
1 year ago

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!

Dien
Dien
1 year ago
Reply to  Dien

Now my Android studio is downloading. I think the problem is solved.

lurkingleo
lurkingleo
1 year ago

It worked and solved my problem. Thankyou

Steini
Steini
1 year ago

Finally. Idiot proof step by step how to solve this. Exactly what I need 🙂

raja
raja
1 year ago

nice one. 100% working

Rodolfo Soriano
Rodolfo Soriano
1 year ago

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.

cos
cos
1 year ago

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.

Mostert
Mostert
1 year ago

I don’t have a Jdk directory, only Jre. What can I do ?

1 year ago
Reply to  Mostert

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!

10 months ago

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

sankar
sankar
3 months ago

really nice lub u lot
 
 

pundlik
pundlik
3 months ago

Thanks, Very clear and simple way presented.

Rabbani
Rabbani
3 months ago

Thank You, It was very helpful

Jackulin
Jackulin
3 months ago

Easy to follow. Clear explanation.

Drs
Drs
2 months ago

javac -version is not recognized the rest echo %JAVA_HOME% worked.

Rashmi
Rashmi
2 months ago

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 »

Last edited 2 months ago by Rashmi
Haroon Siddiqui
Haroon Siddiqui
1 month ago
Reply to  Rashmi

Can you share the link of that video so that we too can work on Java properly and quickly.

nahid
nahid
2 months ago

thank you very much

Sakshi
Sakshi
2 months ago

cmd needs to be opened as administrator otherwise it will not show JAVA_HOME path

Jayanth
Jayanth
2 months ago

Thank you, works perfectly fine.

soniya
soniya
1 month ago

Need help to set system path

Habib Ullah
1 month ago

Thanks .. Dear … so simple and accurate

Azhwani
1 month ago

Thank you for the clear instructions!