How to Set JAVA_HOME on Windows (Step-by-Step Guide)

This tutorial shows how to set the JAVA_HOME environment variable on Windows 10 or 11. Setting JAVA_HOME allows tools like Maven, Gradle, and IDEs to find and use your installed Java Development Kit (JDK).

Table of Contents

Technologies Used:

  • Java 21
  • Windows 10/11

1. Open Advanced System Settings

In the Windows search bar (next to the Start button), type advanced system settings, and click View advanced system settings.

advanced system setting

2. Open Environment Variables

In the System Properties window:

  • Go to the Advanced tab
  • Click the Environment Variables… button

environment variables

3. Create JAVA_HOME Variable

In the System variables section:

  • Click the New… button
  • Set the Variable name to JAVA_HOME
  • Set the Variable value to your JDK installation path (do not include the \bin folder)

Example:
C:\Program Files\Java\jdk-21
C:\Program Files\Java\jdk-21\bin

add java_home

4. Add JAVA_HOME to PATH

To make Java tools accessible from the command line, we must update the PATH variable.

4.1 Older Windows Versions

If you see a single-line text box, append this at the end of the value:

old path edit

4.2 Newer Windows 10/11

If the editor shows a list, click New, and add:

new path add

5. Test JAVA_HOME and Java

Open Command Prompt and run:


java -version
javac -version
echo %JAVA_HOME%

C:\Users\mkyon>java -version
openjdk version "21.0.8" 2025-07-15 LTS
OpenJDK Runtime Environment Temurin-21.0.8+9 (build 21.0.8+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.8+9 (build 21.0.8+9-LTS, mixed mode, sharing)

C:\Users\mkyon>javac -version
javac 21.0.8

C:\> echo %JAVA_HOME%
C:\Program Files\Java\jdk-21

6. Why Set JAVA_HOME?

By setting JAVA_HOME:

  • Java tools (like Maven, Gradle, and IDEs) can locate the JDK easily
  • Java commands like java, javac, jstack, etc., are available system-wide
  • It helps avoid conflicts between multiple Java versions

7. References

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

122 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Radhnatha
10 years ago

Hii,
Mkyong i have windows 10 .i have installed jdk1.8.0_77 and also include jre1.8.0_77.first i setup envirment as your avobe instruction.Then i go to cmd promt type java -version run successfully but when i type javac -version error is occured i.e ‘javac’ is not recognized as an internal or external command,

operable program or batch file.

McDonald Trump
6 years ago
Reply to  Radhnatha

Okay the problem here is that adding %JAVA_HOME%\bin to the path file DOES NOT WORK. Instead, go to file explorer and location the bin folder inside your jdk directory, copy the folder path and add it to the path file. This should resolve javac. In the future, authors should understand what does and doesn’t work before writing a tutorial.

Gurusamy
6 years ago
Reply to  Radhnatha

after completing the system variable settings you better close the command prompt and open again and then you try these commands. For me it worked like that only

swapna
6 years ago
Reply to  Gurusamy

This works. Thanks.

berik
6 years ago
Reply to  Gurusamy

that works))) thx man!!!

vino
6 years ago
Reply to  Gurusamy

thanks buddy

Guest
6 years ago
Reply to  Gurusamy

This.

Michael
6 years ago
Reply to  Radhnatha

I had the same problem, “javac -version” was not being recognised.
So I googled and came across a “stackoverflow.com” article. It mentioned about using location the JDK bin folder.
So I first added “%JAVA_HOME%\bin”
Then I added my address for JDK bin folder.
And that seem to fix my “javac -version” problem.
I don’t know if this is the best “solution”, I’m a noob, just learning.
Here’s a link to the article:
https://stackoverflow.com/questions/44344519/getting-javac-is-not-recognised-as-internal-or-external-command-operable-progr

Sam
7 years ago
Reply to  Radhnatha

try java -version instead. That’ll work after you’ve set the path.

sameeee
9 years ago
Reply to  Radhnatha

i now fixed it by adding a semicolon before appending it to the path.

sameeee
9 years ago
Reply to  Radhnatha

this is also my question, is there any explanations now as to why javac -version didn’t work?

Epredator
9 years ago
Reply to  sameeee

when you write paths do it without any white spaces.

Carlos
7 years ago

Hi Mykong.
when i type ‘echo %JAVA_HOME%’ I only get ‘ %JAVA_HOME%’ as the response

lenny
7 years ago

Hi Mykong.
when i type ‘echo %JAVA_HOME%’ I only get ‘ %JAVA_HOME%’ as the response

venkat
4 years ago
Reply to  lenny

Used Command prompt instead of power shell for “echo %JAVA_HOME%” to work

Marcin
6 years ago
Reply to  lenny

I had the same problem. Try to write command in “Command Prompt” insted of Powershell

Alexandra Erdely
6 years ago
Reply to  lenny

I have the same problem

Alex
6 years ago

instead of adding %JAVA_HOME%\bin to the system variable, I put the whole path like C:\Program Files\Java\jdk1.8.0_201\bin and it worked

Leo
4 years ago
Reply to  Alex

both methods do not seem to work for me. The java -version command works though.

salih kut
6 years ago
Reply to  Alex

This one worked for me thanks

KOns
6 years ago
Reply to  Alex

Seems in some cases that placeholder method does not work out… same issue on my engine.

Ankit Jain
10 years ago

Windows+pause key works in windows 10? because that can also help in opening advance system settings dialog…

yogiraj tambade
9 years ago
Reply to  Ankit Jain

THANK YOU FOR SHORTCUT BROTHER—-

mkyong
10 years ago
Reply to  Ankit Jain

Thanks for your shortcut, yes it works. Windows key + Pause Key will prompts the “advance system settings”

srinivas
6 years ago
Reply to  mkyong

Hi am getting error but in command prompt java is working fine . but having an issue with maven.. pls help me am using java1.8 and windows10 os

Joshua
9 years ago

Windows 10 Path-section fix.

If you click edit on the paths section and it has 4 of them or more, just ADD a new path and make it the ‘%JAVA_HOME%bin’
This is what worked for me, there was nothing for me to add it to the end to that was similar to the video, but I made it it’s own option and it worked.

Guest
8 years ago
Reply to  Joshua

how to make it ‘%JAVA_HOME%bin’. I mean I can add a new path and give the path of my java Bin there. what else do I need to do?

Vicky
8 years ago
Reply to  Joshua

Thanks buddy.. This worked for me..

dinesh
7 years ago

javac -version not worked for me windows 10 latest i m using

Lucas Cunha
6 years ago

The year is 2020, and I use this again

cem766
10 years ago

Hi Everyone and Mkyong, Java SE 8 jdk8u_66 I want to set up to Windows 10, I can’t make the JVM, set beyond the flesh I can’t do, please help you be?

mkyong
10 years ago
Reply to  cem766

Sorry, what is your problem?

tyson
11 months ago

java xmx6g how to fix . java version “1.8.0_451”
fribbbels plz ffs …

Gabriel
2 years ago

You really helped me with this one, i couldnt find a solution but now everything works fine.
Best wishes and THANK YOU SO MUCH!

Arpitha
3 years ago

Hi @mkyong, can you please confirm below queries?

  1. why we’re creating New System Variable(i.e JAVA_HOME)? and whats the use of it ? rather creating we can give the complete jdk path till bin in the path directly as (C:\Program files\Java\jdk1.8\bin)
  2. I was suggested to set path for JRE as well till bin folder in path. Can you confirm if this is optional path setting or mandatory ?
Novembre
3 years ago

Thanks! Really appreciated!

Sardorbek
3 years ago

Hello. Thank you very much !

Rajesh
3 years ago

It’s worked perfely! Thanks for your user friendly documentation, which is very helpful for beginers like me. Appreciate your efforts.

farzad
3 years ago

good
tank you so much

Rafa Costa
3 years ago

Hi Mkyong! Thank you very much, Just folowed each step and it’s worked like a charm.

Yasuni Chamodya
4 years ago

Thank You! It worked for me

tito
4 years ago

THANK YOU MISTER

Khawar Munir
4 years ago

Thank you sir.

Wai Yan Aung
4 years ago

Thank you for helping me out.

vrno
4 years ago

How should I install Tomcat under powershell on Windows 10? It reports Invalid path always

Kaba
4 years ago

Very good tutorial, than you so much!

indrajeet singh
4 years ago

C:\Users\HP>javac -version
‘javac’ is not recognized as an internal or external command,
operable program or batch file.

unknown
4 years ago

do you have like button in your post? I feel like you deserved it!

Denys
5 years ago

Thank you, I have no how to use allure without JAVA_HOME.

Veeranjaneyulu
5 years ago

Hi

Can i use any other name instead of java_home

Arpitha
3 years ago
Reply to  Veeranjaneyulu

Yes you can. I tried it works

Vaibhav
5 years ago

In setting the path variable , use the path actul where your JDK (bin ) is stored

el hassane
5 years ago

Thank you very much for the explanation.

name
5 years ago

thank you

Victor Villarrea
5 years ago

java _version
Error: Could not find or load main class _version

Victor Villarrea
5 years ago

Ok… sorry… it’s ” dash – ” NOT “underscore _ ” Never mind.