Sign in

Mac安装brew

发现电脑Homebrew出问题了,打算卸载了重新安装。

先使用以下命令卸载brew

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

然后使用官网上的安装命令

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

发现安装报错

因为国内访问不稳定,所以考虑使用镜像。

# macOS 用户,请使用以下两句命令
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"

git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash -c "$(sed 's|^BREW_REPO=.*$|BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"|g' brew-install/install.sh)"

执行到

/bin/bash -c "$(sed 's|^BREW_REPO=.*$|BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"|g' brew-install/install.sh)"

发现还是报错,说明切换地址没生效。

直接修改install.sh

修改里面的HOMEBREWCOREGITREMOTE以及HOMEBREWBREWGITREMOTE:

HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

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

然后再执行

/bin/bash -c "$(sed 's|^BREW_REPO=.*$|BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"|g' brew-install/install.sh)"

开始下载,这样首次安装也可以使用镜像,速度还可以,快的时候1M以上。

后续按照https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/设置环境变量,替换上游仓库即可。

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store