brew update不动卡死解决方案(Mac下Homebrew更新国内源)

brew update不动卡死解决方案(Mac下Homebrew更新国内源)

先更新下brew:

 ~ % /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Error: The Ruby Homebrew installer is now disabled and has been rewritten in
Bash. Please migrate to the following command:
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

根据上面的提示,安装脚本进行了更新,运行:
 ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:
==> You are using macOS 10.15.
==> We (and Apple) do not provide support for this old version.
This installation may not succeed.
After installation, you will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving any
issues you experience while you are running this old version.

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R youusername:admin /usr/local/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (32/32), done.
remote: Total 37 (delta 30), reused 32 (delta 30), pack-reused 5
展开对象中: 100% (37/37), 18.17 KiB | 197.00 KiB/s, 完成.
来自 https://github.com/Homebrew/brew
 * [新分支]              less-agressive-core-tap -> origin/less-agressive-core-tap
 * [新分支]              setup-homebrew-test     -> origin/setup-homebrew-test
 * [新分支]              sorbet-files-update     -> origin/sorbet-files-update
正在更新文件: 100% (3782/3782), 完成.
HEAD 现在位于 5babb4910 Merge pull request #14349 from MikeMcQuaid/curl_github_api_args
Updated 4 taps (laggardkernel/tap, homebrew/core, homebrew/cask and fwartner/tap).
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

更新完成,查看最新的版本号:

~ % brew -v                                                                                           
Homebrew 3.6.18
Homebrew/homebrew-core (git revision 01b287e0658; last commit 2023-01-12)
Homebrew/homebrew-cask (git revision 83406eb891; last commit 2023-01-12)

再更新国内源(中国科技大学):

~ % cd "$(brew --repo)"                                                                            
 Homebrew % git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

 #更新Homebrew-core
 Homebrew % cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
 homebrew-core % git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

 #更新Homebrew-cask(最重要的一步,很多更新完国内源依然卡就是没更新这个)
 homebrew-core % cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
 homebrew-cask % git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

 更新HOMEBREW_BOTTLE_DOMAIN(使用zsh的用户):
 homebrew-cask % echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.zshrc
 homebrew-cask % cd
 ~ % source ~/.zshrc
 ~ % cat ~/.zshrc
source ~/.bash_profile
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/

 更新HOMEBREW_BOTTLE_DOMAIN(使用bash的用户):
 echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.bash_profile
 source ~/.bash_profile

更新库

 ~ % brew update-reset 
==> Fetching /usr/local/Homebrew...

==> Resetting /usr/local/Homebrew...
branch 'master' set up to track 'origin/master'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.

==> Fetching /usr/local/Homebrew/Library/Taps/fwartner/homebrew-tap...

==> Resetting /usr/local/Homebrew/Library/Taps/fwartner/homebrew-tap...
branch 'main' set up to track 'origin/main'.
Reset branch 'main'
Your branch is up to date with 'origin/main'.

==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...

==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
branch 'master' set up to track 'origin/master'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.

==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...

==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
branch 'master' set up to track 'origin/master'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.

==> Fetching /usr/local/Homebrew/Library/Taps/laggardkernel/homebrew-tap...

==> Resetting /usr/local/Homebrew/Library/Taps/laggardkernel/homebrew-tap...
branch 'master' set up to track 'origin/master'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.