你可能尝试了很多办法去安装brew,从一开始的网络超时,到一脸蒙的手动安装,本文教你如何正确安装brew
创建Homebrew目录
打开你的终端执行下面的命令,进行创建Homebrew
sudo mkdir /usr/local/Homebrew
同步brew.git库
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git /usr/local/Homebrew
添加环境变量
sudo ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew
同步core库
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
同步cask
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
提权
sudo chown -R $(whoami) /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/Homebrew
查看版本号
brew -v
更换镜像源
此时你安装东西的话,还是会感受到超时的力量,所以我们需要更换国内镜像源
替换homebrew默认源
cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
bash用户:
echo ‘export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles‘ >> ~/.bash_profile
source ~/.bash_profile #刷新
zsh用户
echo ‘export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles‘ >> ~/.zshrc
source ~/.zshrc #刷新
记得要更新
brew update