MacOS Homebrew 镜像加速配置

Summary: Author: 张亚飞 | Read Time: 2 minute read | Published: 2022-03-30
Filed under Categories: LinuxTags: Note,

MacOS Homebrew 镜像加速配置

  • 更换 brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

查看 brew 配置

$ brew config
HOMEBREW_VERSION: 4.0.20
ORIGIN: https://mirrors.aliyun.com/homebrew/brew.git
HEAD: 8917acac9560f8e2846eedc4181470f0345f6db8
Last commit: 4 days ago
Core tap JSON: 03 Jun 03:25 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_BOTTLE_DOMAIN: https://mirrors.aliyun.com/homebrew/homebrew-bottles
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.3 build 1403
Git: 2.39.2 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.87.0 => /usr/bin/curl
macOS: 13.3.1-arm64
CLT: 14.3.0.0.1.1679647830
Xcode: 14.3
Rosetta 2: false

可以看到 ORIGIN 已经替换 https://mirrors.aliyun.com/homebrew/brew.git

更换 homebrew-core.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

brew update 命令添加 -vvv 可以查看执行日志,添加完 aliyun 镜像后发现拉取仍然很慢

$ brew update -vvv
Checking if we need to fetch cask.jws.json...
Checking if we need to fetch formula_tap_migrations.jws.json...
Checking if we need to fetch cask_tap_migrations.jws.json...
...

配置

export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.aliyun.com/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.aliyun.com/homebrew/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.aliyun.com/homebrew/homebrew-core.git"

清华源配置示例

export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

再次执行发现速度飞快

参考


MacOS M1 brew install python 报如下错

Error: Cannot install in Homebrew on ARM processor in Intel default prefix

解决办法

cd /opt
sudo mkdir homebrew
sudo chown $(whoami):admin homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
export PATH="/opt/homebrew/bin:$PATH"

Comments

Cor-Ethan, the beverage → www.iirii.com