Setting the Default Java Version on macOS
Determining the current default Java version installed on a Mac can be achieved by executing the command /usr/libexec/java_home -V. This command lists the installed Java Virtual Machines (JVMs) along with their paths.
To modify the default Java version, follow these steps:
-
Identify the desired JVM: Select the JVM with the desired version and path from the list provided by /usr/libexec/java_home -V.
-
Set the JAVA_HOME environment variable: Use the command export JAVA_HOME=/usr/libexec/java_home -v ` to set the JAVA_HOME variable to the path of the selected JVM.
-
Persist the change: To ensure the default Java version persists across terminal sessions, add the export JAVA_HOME… line to the shell's init file. For Bash, use the following command: export JAVA_HOME=$(/usr/libexec/java_home -v 1.8). For Fish, use: set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8). For Zsh, update the .zshrc file with the following: export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0).
After completing these steps, the default Java version will be updated. Running java -version will display the active Java version.
The above is the detailed content of How Do I Set the Default Java Version on My macOS System?. For more information, please follow other related articles on the PHP Chinese website!