我应该如何在macOS上设置JAVA_HOME环境变量? [英] How should I set the JAVA_HOME environment variable on macOS?
问题描述
我知道这个问题之前已经被问了很多但是我确实已经阅读了,我会告诉你我得到了什么。
I know this question has been asked a lot before but i did read and i will show you what i got.
我将列出我所做的命令我的 OS X Yosemite 10.10.1
I will list the commands that i did in my OS X Yosemite 10.10.1
java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
java -fullversion
java full version "1.8.0_45-b14"
哪个java
/usr/bin/java
Java home变量未设置,因为当我这样做时: echo $ java_home 或回显$ JAVA_HOME 或回显$ Java_Home 终端上什么都没有。
Java home variable is not set because when I do this: echo $java_home or echo $JAVA_HOME or echo $Java_Home i got nothing on the terminal.
做什么这个:ls -l <code>哪个java 我得到了这个:
when doing this: ls -l which java
i got this:
8 lrwxr-xr-x 1 root wheel 74 Nov 12 2014 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
javac -version
javac 1.8.0_45
/ usr / libexec / java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
解决方案我认为在网上阅读后是正确的
The solution that I think is correct after reading on internet is
echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.profile
但我害怕测试它,这就是我问你的原因,如果这是正确与否,如果不是我该怎么办?
but i am afraid to test it, that is why i am asking you, if that is correct or not and if not what should i do please?
推荐答案
我不知道为什么你害怕测试,您可以安全地测试这个:
I'm not sure why you are afraid to test, you can safely test this:
在您的终端会话中,输入以下内容:
In your terminal session, input the following:
echo "export JAVA_HOME=`/usr/libexec/java_home`"
这将打印以下行:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
复制上面的内容并将其粘贴到终端窗口,然后按回车键。并执行 java -version
以查看它是否正常工作。如果一切正常,您可以将代码附加到 .profile
:
Copy the above and paste it into your terminal window, then press enter key. and execute java -version
to see it work correctly. If everything is okay, you can attach the code into your .profile
:
但直接添加此行更好想法是因为升级JDK时不必更新 .profile
。
But adding this line directly is better idea because you don't have to update .profile
when you upgrade JDK.
export JAVA_HOME=`/usr/libexec/java_home`
请参阅手册页 java_home 工具。简而言之,它为JAVA_HOME提供了在macOS上正常安装的适当路径
Please refer to the man page for the java_home tool. In short, it provides the appropriate path for JAVA_HOME for a normal installation on macOS
这篇关于我应该如何在macOS上设置JAVA_HOME环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!