To set environment variables for Java on a Windows system, follow these steps:
1. Open System Properties
- Press Win + Pause/Break to open System Properties.
- Alternatively, right-click This PC or My Computer, select Properties, and click Advanced system settings.
2. Navigate to Environment Variables
- In the System Properties window, go to the Advanced tab.
- Click on the Environment Variables button.
3. Set the JAVA_HOME
Variable
- Under System variables, click New.
- In the Variable Name field, enter
JAVA_HOME
. - In the Variable Value field, enter the path to your Java installation directory (e.g.,
C:\Program Files\Java\jdk-XX.X.X
).
4. Add Java to the Path
Variable
- In the System variables section, find and select the
Path
variable, then click Edit. - Click New and add
%JAVA_HOME%\bin
. - Ensure that it is added as a separate entry for proper recognition.
5. Save and Apply Changes
- Click OK to close all dialog boxes and apply the changes.
6. Verify the Configuration
- Open a Command Prompt (
Win + R
, then typecmd
and hit Enter). - Type
java -version
to verify that Java is correctly installed and the path is set. - You can also type
echo %JAVA_HOME%
to check the value of theJAVA_HOME
variable.
Notes:
- Ensure the correct version of the JDK is installed.
- If you encounter issues, check for typos or incorrect paths.
- Restart your Command Prompt or IDE to ensure it recognizes the updated environment variables.