Home > Java > javaTutorial > body text

How to Configure JAVA_HOME on macOS Mojave and Older?

Mary-Kate Olsen
Release: 2024-11-06 03:01:02
Original
380 people have browsed it

How to Configure JAVA_HOME on macOS Mojave and Older?

Configuring JAVA_HOME on macOS Mojave to Lion

Java is an optional component in recent macOS versions. After installation, the JAVA_HOME environment variable may not be set correctly. Here's how to resolve this issue:

With the Java optional package or Oracle JDK installed, add one of the following lines to the ~/.bash_profile file:

  • export JAVA_HOME="(/usr/libexec/java_home -v 1.6)"
  • export JAVA_HOME="(/usr/libexec/java_home -v 1.7)"
  • export JAVA_HOME="(/usr/libexec/java_home -v 1.8)"
  • export JAVA_HOME=(/usr/libexec/java_home)

For openjdk installations using brew, execute sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk for the previous commands to work.

Note: The -v flag has been added as suggested by Jilles van Gurp. This ensures that the correct version of Java is selected.

The above is the detailed content of How to Configure JAVA_HOME on macOS Mojave and Older?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!