- How to set JAVA_HOME environment variable on Windows 10
- About the Author:
- Add comment
- Comments
- Setting the JAVA_HOME Variable in Windows
- Set the JAVA_HOME Variable
- Set the JAVA_HOME variable via the command line
- How to Set JAVA_HOME Environment Variable in Windows 10
- Prerequisites: Install Java on Windows
- How to Set JAVA_HOME Environment Variable in Windows?
- Conclusion
- About the author
- Rafia Zafar
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.
Setting the JAVA_HOME Variable in Windows
To install Confluence manually on Windows, you will need to set an environment variable to point Confluence to the your Java installation directory.
This information is only relevant if you’re installing Confluence manually on a Windows server. If you’re using the installer, you don’t need to do this.
In most cases you should set the JRE_HOME environment variable, but if it is not set, Confluence will use JAVA_HOME.
Related pages
Set the JAVA_HOME Variable
To set the JRE_HOME or JAVA_HOME variable:
- Locate your Java installation directory
If you didn’t change the path during installation, it’ll be something like C:\Program Files\Eclipse Adoptium\jdk-11.0.17.8-hotspot\ or C:\Program Files\Java\jdk-17.0.4.1\ You can also type where java at the command prompt.
Windows 7 – Right click My Computer and select Properties >Advanced
Windows 8 – Go to Control Panel >System >Advanced System Settings
Windows 10 – Search for Environment Variables then select Edit the system environment variables
- JAVA_HOME if you installed the JDK (Java Development Kit)
or - JRE_HOME if you installed the JRE (Java Runtime Environment)
You’ll need to close and re-open any command windows that were open before you made these changes, as there’s no way to reload environment variables from an active command prompt. If the changes don’t take effect after reopening the command window, restart Windows.
Set the JAVA_HOME variable via the command line
If you would prefer to set the JAVA_HOME (or JRE_HOME) variable via the command line:
- Open Command Prompt (make sure you Run as administrator so you’re able to add a system environment variable).
- Set the value of the environment variable to your JDK (or JRE) installation path as follows:
setx /m JAVA_HOME "C:\Program Files\Java\jdk11.0.17.8"
How to Set JAVA_HOME Environment Variable in Windows 10
Java is a modern, well-liked, general-purpose coding language introduced by Sun Microsystems in 1995. It also supported a multi-threading environment in which many small tasks within an application are executed as threads. Various Java-based programs like Tomcat require the location of the Java Development Kit (JDK) on your system. This direction is provided using the JAVA_HOME which is an environment variable used to point toward the installation directory of JDK.
Here, we will demonstrate the approach to set the JAVA_HOME in Windows.
Prerequisites: Install Java on Windows
JAVA_HOME refers to the directory where the JDK is placed. Prior to setting the JAVA_HOME environment, your system must have JDK. Here, we have added a link to our article:
How to Set JAVA_HOME Environment Variable in Windows?
The environment variables are the space where the information about software and programs are stored such as packages, and program location, and also include Windows program information. It provides the environment in which stored or set programs can interact with the operating system. Follow the below-given guide to set up the “HOME_JAVA” environment variable.
Step 1: Open Java Installation Directory
By default, Java JDK is installed in “Program Files”. If you have changed the installation location, navigate to the directory where the Java and JDK is installed. Then, open the “bin” directory of JDK. After that, copy the path from the “Address” bar. Otherwise, follow the below provided path to access the bin folder:
Step 2: Open Environment Variables Settings
Next, make a search for “Environment Variable” in the “Startup” menu and open the displayed setting:
Step 3: Set JAVA_HOME Environment Variables
Click on the “Environment Variables” button to set JAVA_HOME environment variable:
Next, press the “New” button from the “System variables” panel:
Upon doing so, the “New System Variable” wizard will appear on the screen. Set the “Variable Name” as “JAVA_HOME” and in “Variable value” paste the copied path here. Then, hit the “OK” button:
Step 4: Set Path Environment Variable
In order to use Java from the Windows command line, set the Path environment variable. To do so, select the “Path” property from the “System variable” panel and press the “Edit” button:
Next, click on the “New” button and type “%HOME_JAVA%\bin” in the displayed field. Then, hit on the “OK”:
Step 5: Verify Setting of Environment Variable
In the next step, verify whether we have successfully set Environment Variable JAVA_HOME or not. For this purpose, first, open the Window Command prompt from the Startup menu:
Check out the Java version using provided command:
You can see that we have successfully set the environment variable JAVA_HOME in Windows:
We have learned the method to install java and how to set the environment variable JAVA_HOME in Windows.
Conclusion
To set the JAVA_HOME environment variable, you need to install Java on your system. Next, open the directory where you have installed JDK and copy the “bin” directory path from the “Address” bar. After that, open the Control Panel “Environment Variable” settings and set the new environment variable by clicking on the “New” button, then set the Variable name as “JAVA_HOME” and paste the copied path into the Variable value. In this article, we have demonstrated the technique to add JAVA_HOME to the environment variable in Windows 10.
About the author
Rafia Zafar
I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.