How to Set Java Environment Variable in Windows?

Before setting the environment variable it is necessary to understand why we set the environment variable and why they are crucial for our system? Let’s understand How to set the Java environment variable in Windows?

The Environment variables are global system variables that can be accessed by all the processes/users running on the system. They are useful to store system-wide values such as PATH, OS, PC name, User Name, System Root, HomePath, etc.

The steps to set the Environment variable in Windows are as follows:

  1. Open the system properties
  2. Select the Advance System properties
  3. Select Advanced System Settings
  4. Select Environment Variables option
  5. Select New User Variable
  6. Enter Path Name & Value of JDK
  7. Click Ok
  8. Verify the Process

Let’s understand how to set the environment variable in Windows in detail.

First, verify whether the environment variable is set on your machine or not by executing the below command:


If the environment variable is not set on your machine it will throw an error message ‘javac’ is not recognized as an internal or external command”. Consider the following output:

set environment variable

Now, Follow the below steps to set the environment variable in Windows:

Step1: Open the System Properties

To open the system properties right-click on This PC and select the properties option.

Set environment variable on windows

Step2: Select Advanced System Settings

The next step is to select the Advanced System Settings from the left menu.

Advance System settings

Step3: Select Environment Variables option

It will open a dialog window, select the Select Environment Variable option from this window.

environment variable window

Step4:  Select New User Variable

Now, select the New user variable from this window.

new user variable

Step5: Enter Path Name & Value

Type the variable name as PATH andvariable Value.

specify variable name and path

The Variable can be found from the installed directory of the JDK under the bin folder. Navigate your directory where you have installed Java and copy the bin folder location of the JDK.

java environment variable path on windows

Paste this value in the above Variable Value field and click OK to continue.

Step5: Click OK to Finalize

Now, click OK on the main window of the environment variable.

finalize the set up

Now, we have successfully set the environment variable in our system. We can save and run the Java program in any location of our system.

Step6: verify the Process

To verify the process run the javac command. It will display the output as follows:

If your command prompt is not recognizing the javac command, restart your system.

Now, we can save and run the Java program anywhere on the system.

check other Java Tutorials.

Also see,
How to install Java on Windows
How to install Java on Linux
How to Install Java on Mac OS