1、下载脚本
cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh >> brew_install
如果无法访问,修改host,添加以下内容
199.232.68.133 raw.githubusercontent.com
修改brew_install源git仓库
#BREW_REPO = “https://github.com/Homebrew/brew”
BREW_REPO = “git://mirrors.ustc.edu.cn/brew.git”
执行命令进行安装
sh brew_install
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks
Press RETURN to continue or any other key to abort
2、解决安装core/cask失败
==> Tapping homebrew/core
Cloning into ‘/opt/homebrew/Library/Taps/homebrew/homebrew-core’…
fatal: unable to access ‘https://github.com/Homebrew/homebrew-core/’: LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
Error: Failure while executing; git clone https://github.com/Homebrew/homebrew-core /opt/homebrew/Library/Taps/homebrew/homebrew-core
exited with 128.
Error: Failure while executing; /opt/homebrew/bin/brew tap homebrew/core
exited with 1.
Failed during: /opt/homebrew/bin/brew update --force
Control+C 中断安装
cd /opt/homebrew/Library/Taps
mkdir homebrew #如果存在此文件夹就跳过这一步
cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-core.git
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
完成安装
cd ~
sh brew_install
➜ ~ sh brew_install
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /usr/sbin/chown yuanjian:admin /opt/homebrew
==> Downloading and installing Homebrew…
HEAD is now at 4a90a5a5d Merge pull request #10199 from reitermarkus/check-https-content
Already up-to-date.
Warning: /opt/homebrew/bin is not in your PATH.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this install
run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Run
brew help
to get started - Further documentation:
https://docs.brew.sh
➜ ~ brew --version
3、添加到path
brew --version
zsh: command not found: brew #如果可以显示出版本号则跳过此节
vi ~/.zshrc
敲击I键,添加以下内容后,ESC键,后输入 “:wq”保存
export PATH=$PATH:/opt/homebrew/bin
source ~/.zshrc
brew --version
Homebrew 2.7.1
4、替换为国内源
替换核心软件仓库
cd “$(brew --repo)”
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
替换core源
cd “$(brew --repo)/Library/Taps/homebrew/homebrew-core”
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git
替换cask源
cd “$(brew --repo)/Library/Taps/homebrew/homebrew-cask”
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替换Bottles源
echo ‘export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles’ >> ~/.zshrc
source ~/.zshrc
5、检查
brew update
Already up-to-date.