- How to set JAVA_HOME environment variable on Windows 10
- About the Author:
- Add comment
- Comments
- Setup Java Environment Variables
- Java Environment Variables – Setup JAVA_HOME
- Setup Path variable
- Verify that JAVA_HOME and Path variables are set correctly
- How to Setup, Configure JAVA_HOME and JRE_HOME Environment Variables on Windows?
- Let’s get started
- Step-1
- Step-2
- Step-3
- Step-4
- Step-5
- How to verify?
- What is a difference Between JRE and JDK?
- Suggested Articles.
How to set JAVA_HOME environment variable on Windows 10
In this article, you will understand the details about JAVA_HOME environment variable and how to set it on Windows 10.
What is JAVA_HOME?
By convention, JAVA_HOME is the name of an environment variable on the operating system that points to the installation directory of JDK (Java Development Kit) or JRE (Java Runtime Environment) – thus the name Java Home. For example:
JAVA_HOME = c:\Program Files\Java\jdk1.8.0_201
Why is JAVA_HOME needed?
To develop Java applications, you need to update the PATH environment variable of the operating system so development tools like Eclipse, NetBeans, Tomcat… can be executed because these programs need JDK/JRE to function. So the PATH environment variable should include JAVA_HOME :
PATH = Other Paths + JAVA_HOME
Other paths are set by various programs installed in the operating system. If the PATH environment variable doesn’t contain a path to JRE/JDK, a Java-based program might not be able to run. For example, typing java in the command prompt showing this error:
'java' is not recognized as an internal or external command, operable program or batch file.
Or Eclipse will fail to launch:
How to set JAVA_HOME on Windows 10
Here are the visual steps to properly set value for the JAVA_HOME and update the PATH environment variables in order to setup Java development environment on your computer:
1. Firstly, you need to identify the Java home directory, which is typically under C:\Program Files\Java directory. Open My Computer and navigate to this directory, you will see:
Here, the home of JDK is under C:\Program Files\Java\jdk1.80_201 . The version number may vary, depending on the JDK you installed.
2. Open the System Environment Variables dialog by typing environment in the search area on Start menu. Click the suggested item Edit the system environment variables:
The System Properties dialog appears, click the button Environment Variables.
Then you will see this dialog:
3.Create the JAVA_HOME environment variable by clicking the New button at the bottom. In the New System Variable form, enter the name and value as follows:
Click OK, and you will see the JAVA_HOME variable is added to the list.
4.Update the PATH system variable. In the Environment Variables dialog, select the Path variable and click Edit:
Then in the Edit environment variable dialog, double click on the empty row just below the last text line, and enter %JAVA_HOME%\bin as follows:
The percent signs tell Windows that it refers to a variable – JAVA_HOME , and the \bin specifies the location of java.exe and javac.exe programs which are used to run and compile Java programs, as well as other tools in the JDK.
Click OK button to close all the dialogs, and you’re all set. Now you can open Eclipse or NetBeans to verify. Or open a command prompt and type in javac –version , you should see:
You can add the path to the bin directory of Java home directly into the PATH variable. But it’s strongly recommend to follow the above steps to setup a JAVA_HOME variable because many Java programs depend on it.
When you installed a JDK, you might not need to update the system variable because the installer already did it for you.
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.
Add comment
Comments
Thank you for this helpful article !
With your help I managed to get rid of an annoying message poping every minute.
Thanks, Minh. I was having a fit getting jEdit to work despite Java being installed. The alternate method adding the literal path did not work. Your method with JAVA_HOME does work.
Setup Java Environment Variables
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.
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
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
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
4. This would open the System Properties window as shown below. Now from the Advanced Tab, click on Environment Variables button
5. From the Environment Variables window, click on New button from System variables section
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
7. Click on OK button. You will see that JAVA_HOME variable has now been added in 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
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
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
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
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
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.
How to Setup, Configure JAVA_HOME and JRE_HOME Environment Variables on Windows?
In order to run Java application you need to have first installed Java on your Mac or Windows laptop or desktop.
It’s absolutely required to complete Java setup right way for your production & development applications. If you are a first time Java user then first step is to go to official Oracle website and download JDK.
Below detailed steps will help also if you have below questions:
- How to fix JAVA_HOME error while starting Tomcat Server?
- Why i’m getting jre_home is not defined correctly tomcat error?
- How to set jre_home environment variable?
- jre_home on windows
- Difference between java_home vs jre_home
- How to set jre_home via command line?
In this tutorial we will discuss how to install Java, setup JRE_HOME & JAVA_HOME environment variables on Windows platform only. For Mac and Linux, I’ll publish another tutorial with all detailed steps later.
Let’s get started
Step-1
Configure JAVA_HOME / JRE_HOME Environment Variables
- Go to official Oracle site and Download JDK binary
- Click on Java Download
- Accept License Agreement
- Download binary next to Windows x64
Step-2
- Double click on .exe file and it will install JDK and JRE both on your Windows Laptop/Desktop
- By default it will install JDK and JRE at location: C:\Program Files\Java folder
Step-3
- Now minimize all windows and you will see Desktop icon (check this screenshot)
- Right click on it
- Click on Properties
- Click on Advanced System Settings link as you in above diagram
Step-4
Step-5
- New Pop-up Window will appear
- Click on New…
- Enter JAVA_HOME as variable name and C:\Program Files\Java\jdk1.8.0_121 as Value
- Enter JRE_HOME as variable name and C:\Program Files\Java\jre1.8.0_121 as Value
- Click OK button
- Exit System Properties window
At this time, you are all set.
How to verify?
How to verify if JAVA_HOME and JRE_HOME environment variables setup correctly or not?
- Just open command prompt
- Type java -version
- It will print installed Java details as shown below
That’s it. Let me know if you face any issue installing Java on your laptop. Make sure to update Java version number as per your installation in above steps. Happy coding and happy open sourcing.
What is a difference Between JRE and JDK?
Ideally JRE provides runtime environment for your application. While running your development or production environment, you just need JRE.
On other end, while you are developing Java application , JDK provides more debugging and development functionalities which wont part of JRE.
If you liked this article, then please share it on social media. Have a question or suggestion? Please leave a comment to start the discussion.