How to set up environment variables in Java?

To set up the environment variables for Java, you can follow these steps:

  1. 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.
  2. Open the Control Panel.
  3. Locate and click on “System and Security” in the control panel.
  4. Click on the “System” tab on the “System and Security” page.
  5. Click on “Advanced system settings” on the left side of the “System” page.
  6. Click on “Environment Variables” in the “System Properties” dialog box.
  7. In the “Environment Variables” dialogue box, you will see two sections: User variables and System variables.
  8. 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).
  9. 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.
  10. In the system variables section, locate and select the variable called “Path”, then click on “Edit”.
  11. In the “Edit Environment Variables” dialog box, click on “New”, then enter the variable value as “%JAVA_HOME%\bin”.
  12. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *