Home > Java > javaTutorial > How Do I Set a Default Java Version on macOS?

How Do I Set a Default Java Version on macOS?

Susan Sarandon
Release: 2024-12-14 11:19:11
Original
1028 people have browsed it

How Do I Set a Default Java Version on macOS?

How to Set the Default Java Version on macOS

Changing the default Java version on a Mac requires modifying environment variables. Here are the steps:

Run the following command to view available Java versions:

/usr/libexec/java_home -V
Copy after login

Select the desired Java version (e.g., 1.8.0_05) and export the JAVA_HOME environment variable using:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_05`
Copy after login

Alternatively, specify only the major version:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Copy after login

Verify the default Java version:

java -version
Copy after login

Add the export command to your shell's initialization file. For example, in Bash:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Copy after login

For Fish:

set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8)
Copy after login

For Zsh (in .zshrc file):

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)
Copy after login

Save the changes and source the file:

source ~/.zshrc
Copy after login

Confirm the updated default Java version:

echo $JAVA_HOME
java -version
Copy after login

The above is the detailed content of How Do I Set a Default Java Version on macOS?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template