Setting the path variable for Java

Have a dream? Start learning your way toward it with courses from $12.99. Shop now for extra savings1px

I had installed Java on a Windows 10 system as part of the installation of the Eclipse integrated development environment (IDE), which did not add the directory where the java.exe and javac.exe executable files were installed. I could temporarily add the directory where Eclipse installed those files to the path environment variable—see Running java from an Eclipse installation from the command line—but I didn't want to continue to have to do that every time I wanted to compile a Java program at a command prompt or run one from a command-line interface (CLI). So I added the path to the executable files to the system-wide path environment variable so it would be permanent and apply to all accounts on the system. You can do so by the following steps:

  1. Type advanced system settings in the Windows "Type here to search" field and then click on View advanced system settings when you see that listed.

    View advanced system
settings

  2. You will need to provide authorization credentials for an administrator account to modify the settings. When you do so, under the Advanced tab for System Properties, you will see an Environment Variables button; click on it.

    System Properties - Advanced

  3. When you click on the Environment Variables button, you will see the environment variables for the administrator account you are using at the top of the window and the system environment variables that apply to all accounts on the system at the bottom.

    Environment Variables

  4. Click on the Path variable in the bottom of the window under System variables to select it, then click on Edit to add to the path.
  5. At the Edit environment variable window, double-click on the first blank row in the list of directories to add a directory to the path. Type the full path to the directory you wish to add or paste it into the field.

    Edit Environment Variable

  6. When you've added the new directory, click on OK. In this case I added C:\Users\Jim\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_18.0.1.v20220515-1614\jre\, since that is where Eclipse installed the java.exe and javac.exe files. The account name will, of course, vary depending on the account under which you installed Eclipse, when Java wasn't previously installed on the system.

    Java added to path

  7. You can then click on OK to close the Environment Variables window.

You should then be able to open a new command prompt window and run the java or javac executable programs. It won't work for a command prompt window you had open prior to updating the path environment variable, but should work in a new command prompt window.

Related articles:

  1. Running java from an Eclipse installation from the command line
  2. Obtaining a command prompt in Windows 10