• Skip to main content
  • Skip to primary sidebar

AutomationTestingHub

Selenium, Appium, Cucumber and more !!!

Setup Java Environment Variables

March 2, 2023 by anish 3 Comments

This article provides you with detailed steps on how to setup Java environment variables – mainly JAVA_HOME and PATH variables. These environment variables point to the folder location where Java is installed. These variables are mainly required by some external programs and tools to figure out where Java is installed on your machine.

In our previous article on Java Download and Installation, you would have seen that it’s very likely to have multiple versions of Java installed on your machine. In such a scenario, setting up Java environment variables becomes more important so that you can point to the exact location of the latest version of Java. Let us now check the detailed steps on how to setup these variables.

Multiple Java versions installed

Java Environment Variables – Setup JAVA_HOME

1. As the first step, please copy the folder location where the latest version of JDK is installed. In our previous article on downloading and installing Java, we had installed JDK at the default location (C:\Program Files\Java). If you have also done the same then open that location

Java Environment Variables - JDK folder in Java

2. Now open the JDK folder. If you have multiple JDK folders, then open the one which represents the latest version, and copy the folder location. As per the below screenshot, we are copying this folder location – C:\Program Files\Java\jdk-17

Copy JDK folder location for JAVA_HOME

3. You have to now open environment variables window in your machine. To do this, click on Search icon and then type environment variables in the search bar. Click on Edit the system environment variables option to open it

Open Computer - Properties

4. This would open the System Properties window as shown below. Now from the Advanced Tab, click on Environment Variables button

Environment Variables button in Advanced Tab

5. From the Environment Variables window, click on New button from System variables section

Add new value (JAVA_HOME) in System Variables

6. Enter JAVA_HOME in Variable Name field and JDK folder location (C:\Program Files\Java\jdk-17) in Variable value field as shown in below image. Please enter the correct folder location that you have in your machine

Set JAVA_HOME variable and its path

7. Click on OK button. You will see that JAVA_HOME variable has now been added in System Variables.

JAVA_HOME variable added to System variables

If you already have JAVA_HOME previously set, then you can click on Edit button to modify its value. You have now successfully setup JAVA_HOME variable. Let us now check how to setup the Path variable.

Setup Path variable

Path variable refers to the location of the bin folder inside the JDK folder. Since you have already setup the JDK folder location using JAVA_HOME variable, you can use JAVA_HOME reference to setup the bin folder location. Let’s see the steps to do this –

1. Open your latest JDK folder and check that it has bin folder in it

JDK bin folder for PATH variable

2. Now open this bin folder and copy the entire folder location. For us, this folder location is – C:\Program Files\Java\jdk-17\bin

Copy bin folder location in JDK

3. Since the JDK folder location is already represented by JAVA_HOME variable, so we can replace the location of JDK folder with JAVA_HOME like this – %JAVA_HOME%\bin

4. In the Environment variables window, check that there is a variable called Path under System variables. Please note that Path is an existing variable and we would edit it to add the bin folder location

PATH variable in System variables

5. Select the Path variable and click on Edit button. Edit environment variable window would be opened

6. Click on New button. A new line is highlighted in the window. Add JDK bin path %JAVA_HOME%\bin as shown in the below image

Add bin folder location to PATH variable

7. Click on Ok button. bin folder location is now added in the Path variable

8. Close the Environment variable window by clicking on Ok button. With this, we have now successfully setup Path variable as well

Verify that JAVA_HOME and Path variables are set correctly

After you have added JAVA_HOME and Path variables, it’s time to check if the variables are set correctly. Follow the steps given below to check this –

1. Open command prompt

2. Run the command javac -version. This should show the javac version number. Verify that this version number is same as the latest JDK version (from JDK folder name). You can also run the command where javac. This command should show the JDK bin folder location. This should be the same folder location that you had set in the Path variable

javac -version and where javac commands

Both these commands verify that JAVA_HOME and Path variables have been setup correctly. With this, we complete our section of Java download, install and setup.

If you face issues with any of the steps mentioned in this article, then please feel free to contact us using the comments section.

Filed Under: Appium, Java, Selenium

Primary Sidebar

Automation Testing Hub

Tutorials Guide

Write test scripts in BDD format using our Cucumber Selenium Tutorial

Use our Appium Tutorial Series to setup Appium from scratch

Categories

  • Android
  • Appium
  • Cucumber
  • Java
  • Playwright
  • Selenium
  • Tosca

Recent Posts

  • Appium Inspector – Download and Install
  • How to download Chromedriver for Selenium
  • Run Playwright tests on different browsers
  • Playwright Automation Testing Tutorial
  • Selenium IDE Chrome Download

Recent Comments

  • Run Playwright tests on different browsers - AutomationTestingHub on Playwright Automation Testing Tutorial
  • Confluence: CPSSoft Test Framework on Appium Inspector – Download and Install
  • Playwright Automation Testing Tutorial - AutomationTestingHub on Download and Install – Node.js and NPM
  • Chrome浏览器在使用Java的Appium中无法启动。 | JAVA语言的经验与见解 on 2 Ways to find appPackage and appActivity name of your App
  • Appium Inspector Tutorial - AutomationTestingHub on Download and Install Appium 2 Server

Archives

  • January 2024
  • July 2023
  • March 2023
  • February 2023
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016

Latest Selenium 3 Guide

Are you using the latest version of Selenium WebDriver? It provides lot better support for the latest browser versions. Check it out here - Setup Latest Selenium WebDriver

Categories

  • Android
  • Appium
  • Cucumber
  • Java
  • Playwright
  • Selenium
  • Tosca

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in

Go to mobile version