How to set up environment variables in Java?
To set up the environment variables for Java, you can follow these steps:
- Firstly, you need to make sure that Java Development Kit (JDK) is already installed on your computer. If it is not installed yet, please download and install JDK first.
- Open the Control Panel.
- Locate and click on “System and Security” in the control panel.
- Click on the “System” tab on the “System and Security” page.
- Click on “Advanced system settings” on the left side of the “System” page.
- Click on “Environment Variables” in the “System Properties” dialog box.
- In the “Environment Variables” dialogue box, you will see two sections: User variables and System variables.
- If you only want to set the Java environment variable for the current user, click “New” in the User Variables section, and then enter “JAVA_HOME” as the variable name with the JDK installation path as the variable value (for example: C:\Program Files\Java\jdk1.8.0_221).
- If you want to set the Java environment variable to be effective for all users, click on “New” in the system variable section, and enter the variable name as “JAVA_HOME” and the variable value as the JDK installation path.
- In the system variables section, locate and select the variable called “Path”, then click on “Edit”.
- In the “Edit Environment Variables” dialog box, click on “New”, then enter the variable value as “%JAVA_HOME%\bin”.
- Click the “OK” button, then close all open dialog boxes.
Now that you have successfully set up the Java environment variables, you can open a command prompt window and enter the command “java -version” to verify if the settings are effective.