macOS Mojave (10.14) 到 Lion (10.7) 上的 JAVA_HOME 在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6588390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?
提问by Olivier Refalo
Java is an optional package on the latest versions of macOS.
Java 是最新版本 macOS 上的可选包。
Yet once installed it appears like the JAVA_HOMEenvironment variable is not set properly.
然而,一旦安装,它看起来像JAVA_HOME环境变量没有正确设置。
采纳答案by Olivier Refalo
With the Java optional packageor Oracle JDKinstalled, adding one of the following lines to your ~/.bash_profilefile will set the environment variable accordingly.
随着Java的可选包或甲骨文的JDK安装,添加以下行到你的一个在〜/ .bash_profile文件将设置相应的环境变量。
export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
Update: added -vflag based on Jilles van Gurpresponse.
更新:根据Jiles van Gurp响应添加-v标志。
回答by Cawflands
The above didn't work for me with Amazon's EC2 tools, because it expects bin/java
etc. underneath JAVA_HOME
. /System/Library/Frameworks/JavaVM.framework/Home
did work.
以上对我使用 Amazon 的 EC2 工具不起作用,因为它期望bin/java
下面的等JAVA_HOME
。/System/Library/Frameworks/JavaVM.framework/Home
没有工作。
回答by EGHM
On Mac OS X Lion, to set visualgc to run, I used:
在 Mac OS X Lion 上,要设置 visualgc 运行,我使用了:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
回答by Jilles van Gurp
/usr/libexec/java_home
is not a directory but an executable. It outputs the currently configured JAVA_HOME and doesn't actually change it. That's what the Java Preferences app is for, which in my case seems broken and doesn't actually change the JVM correctly. It does list the 1.7 JVM but I can toggle/untoggle & drag and drop all I want there without actually changing the output of /usr/libexec/java_home
.
/usr/libexec/java_home
不是目录而是可执行文件。它输出当前配置的 JAVA_HOME 并且实际上并没有改变它。这就是 Java Preferences 应用程序的用途,在我的情况下,它似乎已损坏并且实际上并没有正确更改 JVM。它确实列出了 1.7 JVM,但我可以切换/取消切换和拖放我想要的所有内容,而无需实际更改/usr/libexec/java_home
.
Even after installing 1.7.0 u6 from Oracle on Lion and setting it as the default in the preferences, it still returned the apple 1.6 java home. The only fix that actually works for me is setting JAVA_HOME manually:
即使在 Lion 上从 Oracle 安装 1.7.0 u6 并将其设置为首选项中的默认值后,它仍然返回了 apple 1.6 java home。唯一对我有用的修复方法是手动设置 JAVA_HOME:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home/
At least this way when run from the command line it will use 1.7. /usr/libexec/java_home
still insists on 1.6.
至少这样,当从命令行运行时,它将使用 1.7。/usr/libexec/java_home
还是坚持1.6。
Update: Understanding Java From Command Line on OSXhas a better explanation on how this works.
更新:从 OSX上的命令行理解 Java 对它的工作原理有更好的解释。
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
is the way to do it. Note, updating this to 1.8 works just fine.
是这样做的方法。请注意,将其更新为 1.8 可以正常工作。
回答by czarcrab
A better (more upgradable) way is to use the following:
更好(更可升级)的方法是使用以下方法:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
This should work with AWS also since it has bin
underneath Home
这也应该与 AWS 一起使用,因为它bin
在 Home 下
回答by Anjan
This answer is related to Mountain Lionand not Lion. I needed to do this for the AWS Command Line Tools. According to the AWS docs, running which java
returns /usr/bin/java
.
这个答案与Mountain Lion而不是 Lion 相关。我需要为 AWS 命令行工具执行此操作。根据AWS 文档,运行which java
返回/usr/bin/java
。
So, I set JAVA_HOME=/usr
in my .bashrc
.
所以,我JAVA_HOME=/usr
在我的.bashrc
.
Apparently, /usr/bin/java
is a symbolic link to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
which makes it all work.
显然,/usr/bin/java
是一个符号链接/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
,可以使它一切正常。
Update
更新
As mentioned in the comment below, this JAVA_HOME
value is not an ideal solution when the JAVA_HOME
environment variable is to be used by things other than the AWS Command Line Tools. It works fine for the AWS Command Line Tools, though, as given in their docs.
正如下面的评论中提到的,JAVA_HOME
当JAVA_HOME
环境变量要被 AWS 命令行工具以外的东西使用时,这个值不是一个理想的解决方案。不过,正如他们的文档中给出的那样,它适用于 AWS 命令行工具。
回答by onpduo
For me, Mountain Lion 10.8.2, the solution most voted does not work. I installed jdk 1.7 via Oracle and maven from homebrew.
对于我,Mountain Lion 10.8.2,投票最多的解决方案不起作用。我通过 Oracle 和自制软件的 maven 安装了 jdk 1.7。
My solution is from the hadoop-env.sh file of hadoop which I installed from homebrew, too. I add the below sentence in ~/.bash_profile, and it works.
我的解决方案也来自我从自制软件安装的 hadoop 的 hadoop-env.sh 文件。我在 ~/.bash_profile 中添加了以下句子,并且它有效。
export JAVA_HOME="$(/usr/libexec/java_home)"
This solution also works for OS X Yosemite with Java 1.8 installed from Oracle.
此解决方案也适用于从 Oracle 安装了 Java 1.8 的 OS X Yosemite。
回答by user1270392
Got the same issue after I upgrade my Mac OS and following worked for me:
升级我的 Mac OS 后遇到了同样的问题,以下对我有用:
cmd>vi ~/.bash_profile
Add/update the line for JAVA_HOME: export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home"
cmd>source ~/.bash_profile or open a new terminal
cmd>vi ~/.bash_profile
添加/更新 JAVA_HOME 行:export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home"
cmd>source ~/.bash_profile 或打开一个新终端
I think the jdk version might differ, so just use the version which you have under /Library/Java/JavaVirtualMachines/
我认为 jdk 版本可能会有所不同,所以只需使用您在 /Library/Java/JavaVirtualMachines/ 下的版本
回答by Archie
Newer Oracle JVMs such as 1.7.0_21-b12 seem to install here:
较新的 Oracle JVM,例如 1.7.0_21-b12 似乎安装在这里:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
回答by Mike Mitterer
My approach is:
我的做法是:
.bashrc
.bashrc
export JAVA6_HOME=`/usr/libexec/java_home -v 1.6`
export JAVA7_HOME=`/usr/libexec/java_home -v 1.7`
export JAVA_HOME=$JAVA6_HOME
# -- optional
# export PATH=$JAVA_HOME/bin:$PATH
This makes it very easy to switch between J6 and J7
这使得在 J6 和 J7 之间切换非常容易