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.8 196 votes
Article Rating
guest
103 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
vanitha
vanitha
4 years ago

Nice Explanation. working fine for me.

Taneisha
Taneisha
4 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
4 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
4 years ago

Thank you for the clear instructions! Help a lot.

Matt
Matt
4 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
4 years ago

Thanks very much for the detailed explanantion

Sahan Pasindu
Sahan Pasindu
4 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
4 years ago

thank you so much.

Sefer
Sefer
4 years ago

Doesn’t work

echo %JAVA_HOME%
%JAVA_HOME%

Marco
Marco
3 years ago
Reply to  Sefer

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

Nick
Nick
4 months ago
Reply to  Marco

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!

Jon Kreski
Jon Kreski
4 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
4 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
3 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
3 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 »

Annie
Annie
1 year ago
Reply to  Kyle

Thank you it helped

Nick Hartley
Nick Hartley
3 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
3 years ago
Reply to  Nick Hartley

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

Alexander Luiz Marinho
Alexander Luiz Marinho
1 year ago
Reply to  Lester Flax

Lester, you help me. But I don’t know why the javac worked only in System Admin Powershell. Thanks…

Dinesh
Dinesh
1 year ago
Reply to  Nick Hartley

Thanks! Nick

Lester Flax
Lester Flax
3 years ago
Reply to  Jon Kreski

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

ulliu
ulliu
3 years ago

Hey good Job, worked out smooth
thank you

susovan
susovan
3 years ago

thank you sir/madam

dalvir kaur
dalvir kaur
3 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
3 years ago
Reply to  dalvir kaur

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

Alexander Luiz Marinho
Alexander Luiz Marinho
1 year ago
Reply to  akd

akd, thank for the help. My javac only work when I moved it for top of the variables.

anon
anon
1 year ago
Reply to  akd

Yes doing this works now, thanks!

Himani
Himani
1 year ago
Reply to  akd

Hey..thanks, moving the configuration to the top in the Path worked for me!

Jeremy
Jeremy
3 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
3 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
3 years ago

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

Ss41
Ss41
3 years ago

Danke schön

Zachary Gancarz
Zachary Gancarz
3 years ago

fixed. THANKS BRO!

AlejoX
AlejoX
3 years ago

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

Bluck Paul
Bluck Paul
3 years ago

Thanks alot for your easy guidence

morteza
morteza
3 years ago

very very good

alkobarier1rub
alkobarier1rub
3 years ago

Works fine for me. Big thanks!

anonymous
anonymous
3 years ago

Thank you guys…

gautam
gautam
3 years ago

thank you

3 years ago

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

Nancy
Nancy
3 years ago

Thank you!

RonnyDee
3 years ago

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

vidy
vidy
3 years 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
3 years ago

Thanks for your help!

Lester Flax
Lester Flax
3 years ago

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

Chas
Chas
3 years 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.

Noyal Joy
1 year ago
Reply to  Chas

Thank you Chas

Dien
Dien
3 years 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
3 years ago
Reply to  Dien

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

lurkingleo
lurkingleo
3 years ago

It worked and solved my problem. Thankyou

Steini
Steini
3 years ago

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

raja
raja
3 years ago

nice one. 100% working

Rodolfo Soriano
Rodolfo Soriano
3 years 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
3 years 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
3 years ago

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

2 years 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!

2 years 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
1 year ago

really nice lub u lot
 
 

pundlik
pundlik
1 year ago

Thanks, Very clear and simple way presented.

Rabbani
Rabbani
1 year ago

Thank You, It was very helpful

Jackulin
Jackulin
1 year ago

Easy to follow. Clear explanation.

Drs
Drs
1 year ago

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

Rashmi
Rashmi
1 year 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 1 year ago by Rashmi
Haroon Siddiqui
Haroon Siddiqui
1 year 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
1 year ago

thank you very much

Sakshi
Sakshi
1 year ago

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

Jayanth
Jayanth
1 year ago

Thank you, works perfectly fine.

soniya
soniya
1 year ago

Need help to set system path

Habib Ullah
1 year ago

Thanks .. Dear … so simple and accurate

Azhwani
1 year ago

Thank you for the clear instructions!