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

cover

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

    you can also use the Windows key + Pause keyboard combo

    01

  2. Next, choose Advanced system settings:
    02

  3. Then, choose Environment Variables:
    03

  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:
    04

  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:
    05

  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:
    06

  9. You'll be then prompted with an empty box for data input. Enter the following: %JAVA_HOME%bin
    07

  10. Click OK three times, 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.