当前位置:   article > 正文

【解决 brew update 时间太久的问题】

brew update

问题

使用 brew install 时会触发 brew update,而update阶段主要是进行homebrew-cask 和 homebrew-core 及一些其他相关依赖的更新,这些依赖都托管在GitHub,由于国内网络访问GitHub本身就比较慢,做大文件下载的速度可想而知会更慢。

初步分析

使用brew update –verbose观察update过程:

# 执行命令
brew update --verbose
  • 1
  • 2

可以发现在从 GitHub fetch 资源时是最罪恶根源。

解决方案两步走

1、更换Homebrew源

目前国内比较好用的brew源有很多,比较推荐使用清华大学开源软件镜像站的,以下是详细配置

# brew 程序本身,Homebrew/Linuxbrew 相同
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 以下针对 mac OS 系统上的 Homebrew
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

# 以下这两个命令行可以不执行,不影响最终结果
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

# 以下针对 Linux 系统上的 Linuxbrew
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

配置完成后,可以到对应的目录下查看git remote配置,如:

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote -v
  • 1
  • 2

看到显示为如下的结果说明已经配置成功:

origin	https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (fetch)
origin	https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (push)
  • 1
  • 2

2、更换 Homebrew-bottles 镜像(影响软件下载速度)

临时替换

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
  • 1

永久替换

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
  • 1
  • 2

至此,已经完成了brew源的切换,可以运行brew update 测试是否正常。

另外,与上文无关的问题:
自己在 ~/.bashrc中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bashrc
发现zsh加载的是 ~/.zshrc文件,而 ‘.zshrc’ 文件中并没有定义任务环境变量。
解决办法:
在~/.zshrc文件最后,增加一行:
source ~/.bashrc

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/760562
推荐阅读