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.
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).
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
- 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.
- Next, choose Advanced system settings:
- Then, choose Environment Variables:
- You will then see two sections: User variables and System variables. We’re going to configure the Java executables to the PATH system variable.
- Now, click on New under the System variables section (highlighted above). In the next screen that follow, add the following entry:
Field Name Value Variable name
- Click OK. The
JAVA_HOMEvariable is now saved under the System variables section.
- We’re halfway there. Now, we’re going to reference the
JAVA_HOMEvariable with the Java executables. Under the list of System variables, look for the PATH variable, and then Edit:
- 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:
- You’ll be then prompted with an empty box for data input. Enter the following:
This means that we’re making sure that any Java command will come from this directory:
- Click OK thrice, until the Advanced system settings windows goes away.
- 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.
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.