How to Configure the Default Java Version in macOS
Introduction
This article provides a comprehensive overview of how to modify the default Java version on a macOS system.
Solution
The first step is to determine the available Java versions:
/usr/libexec/java_home -V
This command outputs a list of versions and their corresponding paths.
To set a specific version as the default, assign the path to the JAVA_HOME environment variable. For example, to set version 1.6.0_65-b14-462:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462`
You can also specify the major Java version:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Verifying the change:
java -version
The output should display the correct Java version.
To make the change permanent, add the export JAVA_HOME… command to your shell's initialization file:
Bash:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Fish:
set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8)
Zsh:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)
Once the change is made, you can source the initialization file to activate it:
source ~/.zshrc
The above is the detailed content of How Do I Set the Default Java Version on macOS?. For more information, please follow other related articles on the PHP Chinese website!