第一步:
安装xcode,可以在AppStore中查询xcode进行安装
第二步:
不能直接使用brew官网提供的在线安装的命令
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
可能会出现如下报错信息
Xcode-select: error: invalid developer directory ‘/Library/Developer/CommandLineTools’ Failed during: /usr/bin/sudo /usr/bin/xcode-select –switch /Library/Developer/CommandLineTools
原因是 Xcode-select
已经在Xcode安装的时候一并安装好,但是路径不是错误中显的/Library/Developer/CommandLineTools
.
解决:
- 在终端上输入
xcode-select -p
可知xcode-select的安装路径是/Applications/Xcode.app/Contents/Developer
,所以要改一下安装的脚本命令 - 先将安装brew的脚本文件下载到本地
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh >> brew_install
- 修改这个
brew_install
的脚本文件,将其中的/Library/Developer/CommandLineTools
统统替换为/Applications/Xcode.app/Contents/Developer
- 可以使用vi打开
brew_install
,在命令模式中输入命令%s/\/Library\/Developer\/CommandLineTools/\/Applications\/Xcode.app\/Contents\/Developer/g
第三步
更改脚本中的资源链接,替换成中国科学技术大学的镜像
就是把这两句
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
更改为这两句
BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git “.freeze
CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git“.freeze
当然如果这个镜像有问题的话,可以换成别的
然后开始安装
/usr/bin/ruby brew_install
看到如下输出信息,表示安装成功
第四步
- 替换homebrew源,执行如下命令
cd "$(brew --repo)”
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core”
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
- 更新brew(确认为最新版本)
brew update
- 设置 bintray镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
第四步
安装你想要的包,例如docker
brew install docker
基本用法:
假定操作对象为 wget,请替换为自己需要的软件包名
操作 命令 | |
---|---|
更新 Homebrew | brew update |
更新所有安装过的软件包 | brew upgrade |
更新指定的软件包 | brew upgrade wget |
查找软件包 | brew search wget |
安装软件包 | brew install wget |
卸载软件包 | brew remove wget |
列出已安装的软件包 | brew list |
查看软件包信息 | brew info wget |
列出软件包的依赖关系 | brew deps wget |
列出可以更新的软件包 | brew outdated |
Homebrew 中文主页
https://brew.sh/index_zh-cn.html
Homebrew Bottles 源使用帮助
http://mirrors.ustc.edu.cn/help/homebrew-bottles.html
Homebrew Cask 源使用帮助
http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html
Homebrew Core 源使用帮助
http://mirrors.ustc.edu.cn/help/homebrew-core.git.html