在使用 Homebrew install的过程中,经常会卡在Updating Homebrew...这个过程中,下面给出几种常用的解决办法:
解决办法一:修改配置文件,永久取消检查更新的操作
不推荐此方法,Homebrew库建议开启更新。
vim ~/.zshrc
# 新增一行
export HOMEBREW_NO_AUTO_UPDATE=true
解决办法二:本次取消检查更新的操作
更新时按住 control + c 之后取消。
brew install composer
Updating Homebrew...
^C
按住 control + c 之后命令行会显示 ^C,就代表已经取消了 Updating Homebrew 操作
然后就会去执行我们真正需要的安装操作了
~ brew install nginx
Updating Homebrew...
^C==> Installing dependencies for nginx: pcre
==> Installing nginx dependency: pcre
......
解决办法三:替换镜像源(推荐)
平时我们执行 brew 命令安装软件的时候,跟以下 3 个仓库地址有关:
brew.git
homebrew-core.git
homebrew-bottles
通过以下代码依次将这三个仓库的镜像源更换为不同的国内镜像源(zsh下)
1. 官方镜像源
# 替换brew.git:
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 替换homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
# 应用生效
brew update
# 删除homebrew-bottles
vi ~/.zshrc
#### 按i进入输入模式,输入模式下删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置,然后按:wq保存并退出
source ~/.zshrc
2. 阿里镜像源
# 替换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
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
3. 清华镜像源
# 替换brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 应用生效
brew update
# 替换homebrew-bottles(根据镜像地址猜测):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
4. 中科大镜像源
# 替换brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替换homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
以上配置中关于homebrew-bottles,分为以下两种情况:
【1】bash用户和zsh用户的命令不同,以上示例中关于homebrew-bottles的替换仅适用于zsh用户。
【2】bash用户请将配置文件zshrc换为bash_profile
下面给出清华大学镜像源给出的替换homebrew-bottles在bash下的代码,其他以此类推。
### 临时替换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
### 长期替换
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
当使用Homebrew安装过程中遇到卡顿,可以尝试修改配置文件永久取消更新检查,或者临时取消更新操作。推荐的方法是替换镜像源,如官方、阿里、清华或中科大的镜像,以加速Homebrew的执行。
894

被折叠的 条评论
为什么被折叠?



