To set the Java path in the environment variable on a Windows system, follow these steps:

Step-by-Step Guide

  1. Install Java JDK:
  • Ensure you have the Java Development Kit (JDK) installed. If not, download and install it from the Oracle website or OpenJDK.
  1. 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>.
  1. 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.
  1. 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”.
  1. 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

  1. Open Command Prompt:
  • Press Windows Key + R, type cmd, and press Enter.
  1. Check Java Version:
  • In the Command Prompt, type java -version and press Enter.
  • You should see the installed Java version information.
  1. 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 to C:\Program Files\Java\jdk-17.
  • Add %JAVA_HOME%\bin to the Path 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here