当/usr/libexec/java_home返回错误时,如何在Macos Monterey中设置Java_home?
我最近获得了这款新的MacBook Pro(2021)16“ Macos Monterey,并尝试安装Java(OpenJDK11)。我安装了Homebrew并使用Brew Install opentjdk@11
安装Java。我在执行时会受到关注。 java - version
命令,
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)
但是当我执行/usr/usr/libexec/java_home
时,我会得到以下内容,
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
在添加java_home之后,我也将其设置为java_home $(/usr/libexec/java_home)
〜/.zshrc
= 的问题
www.java.com
,然后使用brew
重新安装,但仍会遇到相同 “ rel =“ nofollow noreferrer”>
I recently got this new MacBook Pro (2021) 16" with MacOs Monterey and trying to install Java (openjdk11). I installed Homebrew and used brew install openjdk@11
to install java. I get following when executed java --version
command,
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)
But when I execute /usr/libexec/java_home
, I get the following,
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Which I also had set as my JAVA_HOME after adding JAVA_HOME=$(/usr/libexec/java_home)
to ~/.zshrc
.
Even the folder /Library/Java/JavaVirtualMachines/
is empty.
Tried uninstalling according to www.java.com
and then reinstall using brew
but still getting the same issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在自制OpenJDK公式页面上(上次检查:2022年12月19日),
是说的注释:
如果我需要的话,您需要您代码>在外壳中的变量,您可以在
〜/.zshrc
:(使用Macos Monterey和Ventura Update进行测试)中添加它。
On the Homebrew OpenJDK formula page (last check: 19 dec 2022),
there is this note that says:
If like me you need the
JAVA_HOME
variable in your shell, you can add this in your~/.zshrc
:(Tested with MacOS Monterey and Ventura update).
无法解决原始问题,然后使用
brew install -cask temurin11
( https:// .NET/安装/)并没有任何问题。Could not solve the Original Problem then used
brew install --cask temurin11
(https://adoptium.net/installation/) and installed Java with no problem.