brew是mac的包管理工具,相当于ubuntu的apt-get 和 centos 的yum一样。mac默认是没有安装上这个工具包的,需要手动。
##1、需要依赖于Command Line Tools
首先需要安装Command Line Tools,
一种方法可以通过命令行安装
xcode-select --install
如果已经安装会显示
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
否则会显示一个弹窗,点击安装。由于网络原因,可能会装不上,有条件的可翻墙,或者多试几次。
另一种方法,app store会提示更新,直接安装更新也可以。
##2、安装brew
通过命令行安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
会提示
Press RETURN to continue or any other key to abort
直接按return即可。
如果安装失败,八成是网络原因,重新执行brew安装命令
###brew帮助
Further help:
brew commands
brew help [COMMAND]
man brew
https://docs.brew.sh
切换brew源
Step 1 替换brew.git
homebrew托管于github,更新homebrew就是从git上拉取最新的版本。
有时候git的速度也很慢,会导致更新受阻,那么就需要给git仓库换一个远程地址。
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
Step 2 替换homebrew-core.git
替换Homebrew 核心软件仓库的地址。
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
Step 3 替换Homebrew Bottles 阿里镜像源
官方预先编译好的软件会被装在一个bottle里直接下载解压到系统里,无需本地编译。
Bottle是放在bintray上面的,在国内依然不快。可以通过换bottle的源地址来加速bottle的下载
对于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.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
##附录
卸载brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"