32

Updating Homebrew 卡住的解决方案

 3 years ago
source link: https://wsgzao.github.io/post/homebrew-update/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

换了 MacBook 16 寸的电脑正好在使用 brew 安装一些应用,发现一个小问题是每次执行如 brew install ansible 命令停留在 Updating Homebrew... 的时间特别长,在新加坡理论上应该和网络无关,最后按照网络上的方案选择关闭每次检查更新解决。

更新历史

2020 年 10 月 13 日 - 初稿

阅读原文 - https://wsgzao.github.io/post/homebrew-update/

Homebrew 关闭自动更新

通过环境变量关闭 Homebrew 自动更新解决 Updating Homebrew 方法最简单

# 卡在 Updating Homebrew 好久 
brew install ansible
Updating Homebrew...

# 关闭自动更新,在. zshrc 文件中加入下方命令,如果是 bash 请加在. bash_profile 文件中,全局变量可以 sudo vi /etc/profile
vim ~/.zshrc
export HOMEBREW_NO_AUTO_UPDATE=true

# 刷新环境变量 
source ~/.zshrc

Homebrew 镜像源加速

我们平时执行 brew 命令安装软件的时候,跟这三个仓库有关:

  1. brew.git
  2. homebrew-core.git
  3. homebrew-bottles

使用阿里或者清华的 Homebrew 镜像源代替可以进行加速

https://mirrors.aliyun.com/homebrew/

https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

# 替换 brew.git
cd "$(brew --repo)"
git remote set-url 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

# 替换 homebrew-bottles 访问地址 
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# 还原 brew.git
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 还原 homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

# 还原的话就是删除 HOMEBREW_BOTTLE_DOMAIN,上面的是 zsh 的命令,如果是 bash 的话请写在. bash_profile 文件中。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK