英文:
java command not running from JAVA_HOME on Mac Caralina
问题
我在我的 Mac 上安装了 Java 8 和 OpenJDK 11。JAVA_HOME 被设置为 Java 8,但是当运行 java --version 命令时,它指向了 OpenJDK 11。为什么会出现这种情况,我该如何让 java 命令指向 Java 8?
运行以下命令:
echo $JAVA_HOME
java --version
输出为:
/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+11)
OpenJDK 64-Bit Server VM (build 11.0.8+11, mixed mode)
这真的很奇怪。
英文:
I installed java 8 and openjdk 11 on my Mac. JAVA_HOME is set to java 8, but when running java --version, it points to openjdk 11. Why is it happens and how can I make java command point to java 8?
running the command
echo $JAVA_HOME
java --version
output is
/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+11)
OpenJDK 64-Bit Server VM (build 11.0.8+11, mixed mode)
It is so wired.
答案1
得分: 0
将这段代码添加到`~/.zshrc`文件中。当运行java时,JAVA_HOME将作为首选路径。
英文:
export PATH=${JAVA_HOME}:${PATH}
Add this to ~/.zshrc
. JAVA_HOME will be the first choice when running java.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论