MENU

macOS下使用国内镜像安装Homebrew

August 4, 2019 • 技术笔记

一、获取最新安装脚本到本地编辑

  1. cd ~
  2. curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
  3. 编辑 brew_install 文件

    # This script installs to /usr/local only. To install elsewhere (which is
    # unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
    # anywhere you like.
    HOMEBREW_PREFIX = "/usr/local".freeze
    HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
    HOMEBREW_CORE_TAP = "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core".freeze
    HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
    # BREW_REPO = "https://github.com/Homebrew/brew".freeze
    BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze

    注释掉 BREW_REPO = "https://github.com/Homebrew/brew".freeze
    新增行 BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze

二、执行修改后的脚本安装

  1. /usr/bin/ruby ~/brew_install
  2. 当出现 Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'... 就不用等了...等不到的...
  3. Command + C 停止
  4. cd "$(brew --repo)/Library/Taps/"
  5. mkdir homebrew
  6. cd homebrew
  7. git clone git://mirrors.ustc.edu.cn/homebrew-core.git
  8. 继续执行 /usr/bin/ruby ~/brew_install
  9. 看到 Installation successful! 就安装成功了

三、修改 Homebrew 源为国内镜像

替换 Homebrew 默认源

  1. cd "$(brew --repo)"
  2. git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

替换 homebrew-core 源

  1. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
  2. git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

四、brew更新

brew update

五、设置 bintray 镜像

  1. echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
  2. source ~/.bash_profile
Last Modified: February 17, 2020
Archives QR Code
QR Code for this page
Tipping QR Code