美文网首页
用清华源安装 homebrew

用清华源安装 homebrew

作者: Tim_Lee | 来源:发表于2017-11-29 15:07 被阅读0次

系统参数:
OS El Caption version 10.11.6
MacBook Air (13-inch, Mid 2013)

问题

homebrew 是mac 系统的包管理器,类似于 ubuntu 的 apt-get,centos 的 yum,python 的 pip。
但是直接用 homebrew 官网的方式安装,在国内会非常慢,几乎导致homebrew难以使用。
解决方法是先获取 homebrew 的安装文件 brew_install,并替换该文件中的安装源地址。再使用该 brew_install 文件安装就很快。

获取 brew_install 文件

cd ~
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".freezeCORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze,并替换成 BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
    CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git".freeze
    最后得到:
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/Homebrew/brew/tarball/master anywhere you like or
# change the value of HOMEBREW_PREFIX.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze
# BREW_REPO = "https://github.com/Homebrew/brew".freeze
# CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git".freeze

(文件后面内容省略没显示)

使用 brew_install 文件安装 homebrew

/usr/bin/ruby ~/brew_install

把 homebrew 替换成清华的源

在上面的安装完成之后,就可以更换 homebrew 的索引源和二进制包 bottles 源。

1 替换索引的镜像内容(update更新的内容)

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

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

brew update

2 替换 homebrew 二进制预编译包的镜像

对于 bash shell 命令行用户

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

对于 zsh shell:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

参考

清华源官方地址:
1 索引地址
Homebrew 镜像使用帮助
2 bottles 预编译二进制包地址
Homebrew-bottles 镜像使用帮助

修改 brew_install 文件参考:
Mac下使用国内镜像安装Homebrew

更换清华源参考:
知乎: Homebrew有比较快的源(mirror)吗? Neo Tan的回答 2016-11-19更新

修改 ~/.zshrc 文件参考:
Brew、Pip、Yum更换国内源 2017-08-24

相关文章

网友评论

      本文标题:用清华源安装 homebrew

      本文链接:https://www.haomeiwen.com/subject/bloubxtx.html