To set the Java path in the environment variable on a Windows system, follow these steps:
Step-by-Step Guide
- Install Java JDK:
- Ensure you have the Java Development Kit (JDK) installed. If not, download and install it from the Oracle website or OpenJDK.
- Locate the JDK Installation Path:
- Find the directory where the JDK is installed. The default installation path is usually
C:\Program Files\Java\jdk<version>
.
- Open Environment Variables:
- Press
Windows Key + Pause
to open System Properties. - Click on “Advanced system settings” on the left.
- In the System Properties window, click on the “Environment Variables” button.
- Set the JAVA_HOME Variable:
- In the Environment Variables window, click on “New” under the “System variables” section.
- Enter
JAVA_HOME
as the Variable name. - Enter the JDK installation path (e.g.,
C:\Program Files\Java\jdk<version>
) as the Variable value. - Click “OK”.
- Update the PATH Variable:
- In the Environment Variables window, find the
Path
variable in the “System variables” section and select it. - Click “Edit”.
- In the Edit Environment Variable window, click “New” and add
%JAVA_HOME%\bin
. - Click “OK” to close all the windows.
Verifying the Setup
- Open Command Prompt:
- Press
Windows Key + R
, typecmd
, and press Enter.
- Check Java Version:
- In the Command Prompt, type
java -version
and press Enter. - You should see the installed Java version information.
- Check Javac Version:
- Similarly, type
javac -version
and press Enter. - You should see the installed Java Compiler (javac) version information.
Example
If your JDK is installed at C:\Program Files\Java\jdk-17
, then:
JAVA_HOME
would be set toC:\Program Files\Java\jdk-17
.- Add
%JAVA_HOME%\bin
to thePath
variable.
By following these steps, you should have successfully set the Java path in your environment variables. This setup ensures that Java and its tools are accessible from the command line anywhere on your system.