Homebrew安装AdoptOpenJDK8的几个注意事项

Homebrew加速安装AdoptOpenJDK8的步骤

1. 首先确保已经安装好homebrew Cask

2. 安装adoptopenjdk8

brew cask install adoptopenjdk8

可能会遇到错误,或者长时间无法下载。ctrl+c中断安装

Downloading https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jdk_x64_mac_hotspot_8u252b09.pkg

3. 打开如下文件 adoptopenjdk8.rb,使用vim或者textedit

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-versions/Casks/adoptopenjdk8.rb

找到如下一行

url "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk#{version.before_comma}u#{version.after_comma.before_colon}-#{version.after_colon}/OpenJDK#{version.before_comma}U-jdk_x64_mac_hotspot_#{version.before_comma}u#{version.after_comma.before_colon}#{version.after_comma.after_colon}.pkg"

修改为国内源下载

url "https://mirrors4.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/jdk/x64/mac/OpenJDK#{version.before_comma}U-jdk_x64_mac_hotspot_#{version.before_comma}u#{version.after_comma.before_colon}#{version.after_comma.after_colon}.pkg"

保存后,重新执行第二步安装命令

4. 安装时,会遇到如下问题,提示sha256,安装包哈希值不对

ma@mas-MacBook-Pro Library % brew cask reinstall adoptopenjdk8
==> Downloading https://mirrors4.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/jdk/x64/mac/OpenJDK8U-jdk_x64_mac_hotspot_8u252b09.pkg
Already downloaded: /Users/ma/Library/Caches/Homebrew/downloads/61c6bb8fd0f54ed4e318b05b2447079ebc3217519ff708604f5e3e30e72d905d--OpenJDK8U-jdk_x64_mac_hotspot_8u252b09.pkg
==> Verifying SHA-256 checksum for Cask 'adoptopenjdk8'.
==> Note: Running `brew update` may fix SHA-256 checksum errors.
Error: Checksum for Cask 'adoptopenjdk8' does not match.
Expected: 98baa64886b87f91e2c49e5a273899f7b9f4088f46ea17c474e809f61d67e4ad
  Actual: 2a216f3d1345d5206ddc37af34a88d5cfd462f647fd8a1d2e75f77a41bbf3eb5
    File: /Users/ma/Library/Caches/Homebrew/downloads/61c6bb8fd0f54ed4e318b05b2447079ebc3217519ff708604f5e3e30e72d905d--OpenJDK8U-jdk_x64_mac_hotspot_8u252b09.pkg
To retry an incomplete download, remove the file above.
If the issue persists, visit:
  https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/reporting_bugs/checksum_does_not_match_error.md

5. 复制Actual: 国内源安装包的sha256值。

6. 重新打开 adoptopenjdk8.rb, 参看第三步

7. 找到如下行

  sha256 '98baa64886b87f91e2c49e5a273899f7b9f4088f46ea17c474e809f61d67e4ad'

修改为第五步复制的实际sha256

sha256 '2a216f3d1345d5206ddc37af34a88d5cfd462f647fd8a1d2e75f77a41bbf3eb5'

保存退出,并重新安装

brew cask install adoptopenjdk8

8. 至此已经可以顺利从国内的源下载并安装adoptopenjdk8。应该会需要输入管理员账号密码。

Password:
==> Purging files for version 8,252:b09 of Cask adoptopenjdk8
==> Installing Cask adoptopenjdk8
==> Running installer for adoptopenjdk8; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
installer: Package name is AdoptOpenJDK
installer: Installing at base path /
installer: The install was successful.

9. 配置环境变量, 打开 ~/.bash_profile或者~/.zshrc

在最后一行输入

export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"
export PATH=${JAVA_HOME}/bin:$PATH

保存退出,执行source  ~/.bash_profile 或者~/.zshrc

10. 验证java版本

java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.252-b09, mixed mode)

 

你可能感兴趣的:(系统疑难问题解决)