brew install 命令卡在 Updating Homebrew 的原因与解决方法

目录
[隐藏]

brew 在 install 前会默认执行 brew update,它会从 brew 在 Github 的官方源码仓库进行更新。由于 Github 访问速度慢或无法访问而导致更新卡住或失败。

那么我们可以将默认的 Github 源码地址修改为国内的镜像地址来解决这个问题。

1 brew 使用国内镜像源

使用中科大镜像源,步骤参考如下:

# brew
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# homebrew-core.git
cd "$(brew --repo homebrew/core)"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替换 homebrew-cask:如果安装了 cask,这一步也要做
cd "$(brew --repo homebrew/cask)"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 设置二进制预编译包镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# 测试一下
brew update

另外还有清华镜像源可选,步骤参考如下:

# 替换 brew
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换 homebrew-core
cd "$(brew --repo homebrew/core)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 设置二进制预编译包镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

# 最后测试一下
brew update

参考地址: https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

2 还原默认的 Github 源码仓库地址

如果想还原为 Github 官方默认的源码仓库地址,可以按如下步骤操作:

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

3 附:brew 安装与常用命令

brew 是 mac os x 上最流行的包管理工具,使用它安装软件非常的方便。如果你没有安装,那么安装它:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew cask k 是 brew 的一个子集,也就是一个扩展,主要用于有GUI的软件。安装 brew cask

 brew install caskroom/cask/brew-cask

brew 常用命令参考:

brew update                        #更新brew可安装包,建议每次执行一下
brew search php55                  #搜索php5.5
brew tap josegonzalez/php          #安装扩展<gihhub_user/repo>   
brew tap                           #查看安装的扩展列表
brew install php55                 #安装php5.5
brew remove  php55                 #卸载php5.5
brew upgrade php55                 #升级php5.5
brew options php55                 #查看php5.5安装选项
brew info    php55                 #查看php5.5相关信息
brew home    php55                 #访问php5.5官方网站
点赞 (0)

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code