1.打开终端,输入以下命令:
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
执行之后,/用户/XXX/目录下会出现一个brew_install的文件。
2.打开这个文件
把下面2句
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
PS:现在安装的时候没有CORE_TAP_REPO这一项,添加上这一句
3.执行修改后的文件,在终端输入以下命令:
/usr/bin/ruby ~/brew_install
4.执行中可能会遇到以下的错误:
Error:Checksum mismatch
按照提示删除下载的文件,输入以下命令:
rm -rf /Users/你的用户名/Library/Caches/Homebrew/portable-ruby-2.6.3.mavericks.bottle.tar.gz
重新下载,输入命令:
/usr/bin/ruby ~/brew_install
5. 耐心等待执行,直到出现以下Error:
因为源不通,代码无法下载到本地,解决方法是更换成国内镜像源,执行如下命令,更换到清华的镜像
cd /usr/local/Homebrew/Library/Taps/homebrew
(如果没有homebrew这个文件夹,可以新建一个)
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
6.把Homebrew-core的镜像地址也设置为清华的国内镜像
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
7.执行更新,命令行输入:
brew update
显示Already up-to-date,则安装结束
其他:
执行第5步的时候,刚开始尝试用中科院的镜像,提示以下 错误:
fatal: remote error: access denied or repository not exported: /homebrew-coraccess denied
我以为是iOS新系统下,/usr/local的访问权限导致的。
sudo chown -R $(whoami) /usr/local/* 之后不行。
重新启动时按Command+R去恢复模式执行了csrutil disable命令,但是仍然不行
后来更换了清华镜像安装成功。
本文参考以下文章: