How to set or change the default Java (JDK) version on macOS?
To set the default Java (JDK) version on macOS, you can use the java_home
command line tool. Here's how:
Open a Terminal window.
Use the
/usr/libexec/java_home
command to list the available JDK versions:/usr/libexec/java_home -V
This will list the available JDK versions and their corresponding paths.
To set the default JDK version, use the
-v
option with thejava_home
command and specify the version you want to set as the default. For example:/usr/libexec/java_home -v 11.0.7
This will set the default JDK version to 11.0.7.
To verify that the default JDK version has been set correctly, use the
java -version
command:java -version
This will print the version of the JDK that is currently being used.
Note that these steps will only set the default JDK version for the current user. If you want to set the default JDK version for all users on the system, you will need to use additional steps.