Home  >  Article  >  Java  >  How Do I Set the JAVA_HOME Environment Variable on macOS Mojave (10.14) to Lion (10.7)?

How Do I Set the JAVA_HOME Environment Variable on macOS Mojave (10.14) to Lion (10.7)?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-06 17:10:02742browse

How Do I Set the JAVA_HOME Environment Variable on macOS Mojave (10.14) to Lion (10.7)?

Identifying JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)

Despite being an optional package in recent macOS versions, Java's installation on these systems raises concerns about the incorrect configuration of the JAVA_HOME environment variable.

Solution:

To ensure the environment variable is set appropriately, include the following line in your ~/.bash_profile file, depending on your installed Java version:

  • Java 1.6: export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
  • Java 1.7: export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
  • Java 1.8: export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
  • Default (latest version): export JAVA_HOME=$(/usr/libexec/java_home)

Note for brew-installed OpenJDK:

If OpenJDK was installed via brew on macOS, run the following command to make the above solution work:

sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

Additional Considerations:

  • The -v flag has been added to the java_home command based on Jilles van Gurp's response.
  • Please save the changes you made to the ~/.bash_profile file and restart your terminal to apply them.

The above is the detailed content of How Do I Set the JAVA_HOME Environment Variable on macOS Mojave (10.14) to Lion (10.7)?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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