homebrew安装指定的jdk版本

半兽人 发表于: 2022-10-17   最后更新时间: 2022-10-17 20:55:23  
{{totalSubscript}} 订阅, 2,323 游览
brew install openjdk@11
Error:
  homebrew-core is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/11/manifests/11.0.10
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/11/blobs/sha256:327ca0eb47ef48009be2f97b5ad7756ee856d7673d39b9c601715e0f8450686c
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:327ca0eb47ef48009be2f97b5ad7756ee856d7673d39b9c601715e0f8450686c?se=2022-10-17T11
######################################################################## 100.0%
==> Pouring openjdk@11--11.0.10.big_sur.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have openjdk@11 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> /Users/xxxx/.bash_profile

For compilers to find openjdk@11 you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"

==> Summary
🍺  /usr/local/Cellar/openjdk@11/11.0.10: 654 files, 297.3MB

设置环境变量:

echo 'JAVA_HOME=/Library/Java/Home' >> ~/.bash_profile
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.bash_profile

验证:

$JAVA_HOME/bin/java -version

也可以直接

java -version
更新于 2022-10-17
在线,6分钟前登录

查看java更多相关的文章或提一个关于java的问题,也可以与我们一起分享文章