Mac安装的homebrew慢,更换为国内源。


下载安装文件到本地

打开终端,输入:

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

会在当前目录下创建文件 brew_install

修改镜像源

vim修改文件

vim brew_install

# 注释掉 BREW_REPO = "https://github.com/Homebrew/brew".freeze
改为清华大学的镜像地址

BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze

保存退出

安装

运行

/usr/bin/ruby brew_install

安装中途仍然有较慢的部分,不过相比官方安装方式快多了。

Homebrew 镜像使用帮助

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

注:该镜像是 Homebrew 的 formula 索引的镜像(即 brew update 时所更新内容)。本镜像站同时提供 Homebrew 二进制预编译包的镜像,请参考 Homebrew bottles 镜像使用帮助。

替换现有上游

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

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

brew update

复原
(感谢Snowonion Lee提供说明)

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update

Homebrew-bottles 镜像使用帮助

摘自 https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/

注:该镜像是 Homebrew 二进制预编译包的镜像。本镜像站同时提供 Homebrew 的 formula 索引的镜像(即 brew update 时所更新内容),请参考 Homebrew 镜像使用帮助。

临时替换

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

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

homebrew常用命令

查看homebrew版本 brew -v
查看已安装的包 brew list
安装包 brew install packageName
卸载包 brew uninstall packageName
查找包 brew searck packageName
查看包信息 brew info packageName
更新homebrew brew update
诊断homebrew brew doctor
查看帮助信息 brew -h