Homebrew
介绍
HomeBrew 是 macOS 下的包管理器。安装方式:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
组成部分
HomeBrew 由 4 个仓库组成,分别是:
- homebrew:源代码仓库
- homebrew-core:核心库
- homebrew-cask:macOS 应用和大型二进制文件安装
- homebrew-bottles:预编译的二进制软件包
这四个组成分别对应着 4 个 Git 仓库。
换源
参照 Mac 下 brew 切换为国内源 一文中的方法。
brew、core 和 cask 是通过 git 上游方法更换。bottle 是用环境变量更换。
以中科大为例,抄录如下:
# 替换各个源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# zsh 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
# bash 替换 brew bintray 镜像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 刷新源
$ brew update
另外再抄录切回官方源的方法:
# 重置 brew.git 为官方源
$ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 重置 homebrew-core.git 为官方源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 重置 homebrew-cask.git 为官方源
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
# zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# 刷新源
$ brew update
gcc
默认安装 gcc 是从源码进行编译的,这个耗时实在是太长了。
Installing OpenCV with Brew never finishes 给出了一种方法,加一个参数来安装二进制版本:
brew install gcc --force-bottle
亲测好用,--force-bottle
这个标志记住了。