X
    Categories: Java EE

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 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 in Windows 10



2. Set JAVA_HOME Environment variable

In “System Properties window” click “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

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

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

4.8 196 votes
Article Rating
filip:

View Comments (103)

  • 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 it is worked. and your facebook login authentication app is not working. i mean that CONNECT WITH facebook button above the comment section. :)

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

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

Related Post