Setting or changing the default Java (JDK) version involves updating the system’s environment variables and configuring the Java installation. Here’s a step-by-step guide for various operating systems:
Windows
1. Install the desired JDK version from the official website.
2. Set the JAVA_HOME environment variable:
– Right-click on Computer or This PC and select Properties.
– Click on Advanced system settings on the left side.
– Click on Environment Variables.
– Under System Variables, scroll down and find the JAVA_HOME variable, then click Edit.
– Update the Variable value to the path of the newly installed JDK (e.g., C:\Program Files\Java\jdk-17).
3. Update the PATH environment variable:
– In the same Environment Variables window, scroll down and find the Path variable under System Variables, then click Edit.
– Click New and add the path to the JDK’s bin directory (e.g., C:\Program Files\Java\jdk-17\bin).
4. Verify the default Java version:
– Open a new Command Prompt or PowerShell window.
– Type java -version and press Enter.
macOS (using Terminal)
1. Install the desired JDK version from the official Oracle website or using Homebrew.
2. Set the JAVA_HOME environment variable:
3. Update the PATH environment variable:
– Run the command export PATH=JAVA_HOME/bin:PATH.
4. Verify the default Java version:
– Type java -version and press Enter.
Linux (using Terminal)
1. Install the desired JDK version from the official Oracle website or using the package manager (e.g., apt-get for Ubuntu-based systems).
2. Set the JAVA_HOME environment variable:
3. Update the PATH environment variable:
– Run the command export PATH=$JAVA_HOME/bin:$PATH.
4. Verify the default Java version:
– Type java -version and press Enter.
After completing these steps, the default Java version should be updated to the desired version.