Home  >  Article  >  Java  >  How to Set JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?

How to Set JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?

Barbara Streisand
Barbara StreisandOriginal
2024-11-05 20:25:02205browse

How to Set JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?

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

The installation of Java on recent macOS versions requires additional configuration to set the JAVA_HOME environment variable correctly.

In the absence of a JAVA_HOME setting, add the appropriate line from the following options to your ~/.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)"

Note that you may need to run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk if you installed openjdk via brew.

Additionally, include the -v flag as suggested by Jilles van Gurp for improved accuracy.

The above is the detailed content of How to Set JAVA_HOME 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