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.
/usr/libexec/java_homecommand to list the available JDK versions:
This will list the available JDK versions and their corresponding paths.
To set the default JDK version, use the
-voption with the
java_homecommand 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
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.