Mac 安装 Homebrew

3,927 阅读1分钟

终端输入以下命令

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

可能会出现 以下错误

Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决方法

  1. 打开 raw.githubusercontent.com/Homebrew/in… (打开失败,请搭梯子)
  2. 将内容保存下来,并命名brew_install.rb
  3. 打开brew_install.rb,添加或替换以下代码
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze

CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze
  1. 保存后 在该文件所在的文件夹下打开终端并执行ruby brew_install.rb

不出意外,应该还会出现以下错误

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read:

SSL_ERROR_SYSCALL, errno 54

Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1` exited with 128.

Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.

解决方法

// 执行下面这句命令,更换为中科院的镜像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

// 把homebrew-core的镜像地址也设为中科院的国内镜像

cd "$(brew --repo)" 

git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" 

git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

// 更新
brew update

// 重新安装
ruby brew_install.rb

至此,应该能安装成功了