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

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

Test JAVA_HOME and system path

Test JAVA_HOME and system path

30
Leave a Reply

avatar
23 Comment threads
7 Thread replies
11 Followers
 
Most reacted comment
Hottest comment thread
26 Comment authors
anonymousalkobarier1rubmortezaBluck PaulAlejoX Recent comment authors
newest oldest most voted
vanitha
Guest
vanitha

Nice Explanation. working fine for me.

Taneisha
Guest
Taneisha

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

gravis ultrasound
Guest
gravis ultrasound

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
Guest
eli

Thank you for the clear instructions! Help a lot.

Matt
Guest
Matt

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

Mayowa Olunuga
Guest
Mayowa Olunuga

Thanks very much for the detailed explanantion

Sahan Pasindu
Guest
Sahan Pasindu

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
Guest
Hung vu

thank you so much.

Sefer
Guest
Sefer

Doesn’t work

echo %JAVA_HOME%
%JAVA_HOME%

Jon Kreski
Guest
Jon Kreski

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.

ulliu
Guest
ulliu

Hey good Job, worked out smooth
thank you

susovan
Guest
susovan

thank you sir/madam

dalvir kaur
Guest
dalvir kaur

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?

Jeremy
Guest
Jeremy

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
Guest
Titan

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
Guest
Yaraslau

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

Ss41
Guest
Ss41

Danke schön

Zachary Gancarz
Guest
Zachary Gancarz

fixed. THANKS BRO!

AlejoX
Guest
AlejoX

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

Bluck Paul
Guest
Bluck Paul

Thanks alot for your easy guidence

morteza
Guest
morteza

very very good

alkobarier1rub
Guest
alkobarier1rub

Works fine for me. Big thanks!

anonymous
Guest
anonymous

Thank you guys…