Brew 安装的 Java 无法与系统 java 文件夹进行符号链接

问题描述 投票:0回答:2

我使用 Homebrew 安装了 Java11,并在我的 M1 mbp 上运行命令

brew search java
brew install java11

其中安装的是java版本。然后当我跑步时

brew info java

我明白了

openjdk: stable 17.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✔
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

==> Analytics
install: 229,799 (30 days), 652,569 (90 days), 2,040,179 (365 days)
install-on-request: 64,996 (30 days), 187,761 (90 days), 591,813 (365 days)
build-error: 5,513 (30 days)

我在警告下运行了 sudo 命令,但我不知道它是否做了什么。当我跑步时

Java --version

我明白了

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

我不明白为什么会发生这种情况。我之前已经启动并运行了 Java,但我必须格式化并安装操作系统的新副本,现在当我尝试再次安装 Java 时,我遇到了这个问题。我假设 Homebrew java 安装位置之间的符号链接没有与系统 java 位置链接,但我可能是错的。

java java-11 apple-m1
2个回答
2
投票

我遇到了同样的问题,但是当我运行

brew info java
时,它给了我几个运行步骤:

sudo ln -sfn /Users/${whoami}/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

export PATH="/home/${whoami}/homebrew/opt/openjdk/bin:$PATH"

java -version 
# This should work
# To make the export permanent
echo 'export PATH="/Users/${whoami}/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc 

假设

${whoami}
(您的用户名与您的主文件夹相同)。否则,请将变量替换为您的实际文件夹名称。

另外,看起来你想要java11,你可能在

~/homebrew/opt/

下有它

您可以搜索一下:

find ~/homebrew/ -name '*openjdk*'

您会发现一个类似

openjdk@11
的文件,对我来说它位于
~/homebrew/opt/openjdk@11
中,在这种情况下,您可以导出:

export PATH="/home/${whoami}/homebrew/opt/openjdk@11/bin:$PATH"

而不是

export PATH="/home/${whoami}/homebrew/opt/openjdk/bin:$PATH"

0
投票

对于我来说,通过brew安装temurin17已解决,已经在这里建议: https://stackoverflow.com/a/74260169/8520417

© www.soinside.com 2019 - 2024. All rights reserved.