v2-8f1ea66d5742981916b04879ebd0325c_1200x500.jpg
什么是Homebrew?
简单来说就是一个macOS(或Linux)的包管理器,可以用它来安装你需要的软件,方便卸载跟升级。
安装Homebrew
- 由官网(https://brew.sh/index_zh-cn.html)复制安装命令,输入到bash shell 中。
/usr/bin/ruby -e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"
如安装中出现问题,将https://raw.githubusercontent.com/Homebrew/install/master/install中内容另存为brew_shell 文件。
将brew_shell 中前几行的一个变量做如下替换。
#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
- 用如下命令安装(~要用保存brew_shell的路径替换)。
/usr/bin/ruby ~/brew_install
- 在安装到如下时,关闭命令行!
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
- 重新打开命令行,用清华的镜像站进行clone。
cd /usr/local/Homebrew/Library/Taps/homebrew
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
- 替换homebrew默认源。
cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
- 替换homebrew-core默认源。
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git
- 设置 bintray镜像。
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
- 运行
brew doctor
,可发现git origin已经成功替换。以后可以运行brew update
进行更新。
附录:清华镜像站 https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/
参考资料:
https://zhuanlan.zhihu.com/p/93092044
https://zhuanlan.zhihu.com/p/59805070