Configure Windows PATH System Variable for Java

This is a guide to configure Windows PATH system variable for Java. After you’ve done this, you can start to execute Java commands from the Windows command line. You’ll find these commands useful as you venture through the Java world.

Overview

We’ve written a post before on setting up Java on an Ubuntu or Debian box. It was a rather straightforward process, and easy to set up (as long as you follow the steps one at a time).

Configure Windows PATH System Variable for Java 01
Issue when you first installed Java, without setting the environment variables on Windows

For Windows, the process is similar. For this guide, we’ll be setting up the Java environment on the PATH system variable via the System Properties. In this guide, we’ll be referring to Windows 10, but the same steps should work for other versions of Windows as well.


What You’ll Need:

  • Oracle Java JDK/JRE installed (latest version as of 5th June 2016 is Version 8 Update 91)
  • Windows 7/8/10 or Windows Server 2008/2012

Configure Windows PATH System Variable for Java

    1. First off, open up the System Properties window by:
      • right-clicking on This PC and selecting Properties, or
      • press the Windows key + Pause keyboard combo.
        Configure Windows PATH System Variable for Java 02
        The System Properties of this machine
    2. Next, choose Advanced system settings:
      Configure Windows PATH System Variable for Java 03
      Advanced Settings Window
    3. Then, choose Environment Variables:
      Configure Windows PATH System Variable for Java 04
      List of all current variables in the system
    4. You will then see two sections: User variables and System variables. We’re going to configure the Java executables to the PATH system variable.
    5. Now, click on New under the System variables section (highlighted above). In the next screen that follow, add the following entry:
      Field NameValue
      Variable nameJAVA_HOME
      Variable value<PATH_TO_JAVA>
      <PATH_TO_JAVA>refers to the location of your Java installation directory. For example,C:\Java\jdk1.8.0_91
      Configure Windows PATH System Variable for Java 05
      Adding the JAVA_HOME system variable
    6. Click OK. The JAVA_HOME variable is now saved under the System variables section.
    7. We’re halfway there. Now, we’re going to reference the JAVA_HOME variable with the Java executables. Under the list of System variables, look for the PATH variable, and then Edit:
      Configure Windows PATH System Variable for Java 06
      Now, we’ll edit the PATH system variable
    8. You’ll then be presented with a list of PATH values. These paths come from either installed applications, or ones that are set by Microsoft. When any directory gets passed here, only then their commands can be used in a command line interface. Click on New:
      Configure Windows PATH System Variable for Java 07
      Click “New” to add the path to the Java executables
    9. You’ll be then prompted with an empty box for data input. Enter the following:
      %JAVA_HOME%\bin
      Configure Windows PATH System Variable for Java 08
      This is how the Java PATH variable would look like

      This means that we’re making sure that any Java command will come from this directory:

    10. Click OK thrice, until the Advanced system settings windows goes away.
    11. Now you can test out the PATH system variable update for Java:
      Microsoft Windows [Version 10.0.10586]
      (c) 2015 Microsoft Corporation. All rights reserved.
      
      C:Users\jusuc>java -version
      java version "1.8.0_91"
      Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
          

Pat yourself in the back! You’ve just configure Windows PATH System Variable for Java, and you can begin executing Java commands from the command line.


Extra Thoughts

As you may have noticed, we’ve used the %JAVA_HOME% environment variable to reference the location of the Java executables. By configuring this way, you can just simply update the %JAVA_HOME% without worries. Once done, you will then execute future updated Java commands from the command line.

 

Technology Consultant at ServiceRocket. Great knowledge in Atlassian JIRA. Blogger. Programmer. Anime Vector Artist.