How to set up JDK environment variables in Java
Before setting up JDK environment variables, you need to first download and install JDK.
- Download JDK: Download the JDK version that is suitable for your operating system from the official Oracle website, and proceed with the installation once the download is complete.
- Set up environment variables:
- Open the “Control Panel,” click on “System and Security,” and select “System.”
- Click “Advanced System Settings”, then click “Environment Variables” in the pop-up window.
- In “System Variables”, click on “New” and then enter the following information:
Variable Name: JAVA_HOME
Variable Value: Path to the JDK installation (e.g. C:\Program Files\Java\jdk1.8.0_221) - In “System Variables,” locate the “Path” variable and double-click to edit it.
- Add “%JAVA_HOME%\bin;” at the beginning of the “Variable value” to enable the system to locate the executable files of JDK.
- Click “OK” to save the changes.
- verification of configuration
- Open the Command Prompt window (Press Win+R, type “cmd”, then hit enter).
- If “java -version” input is successful in displaying Java version information, it means the configuration is successful.
After setting up the JDK environment variables, you can use the java command to run Java programs anywhere.