mac修改brew源

jimmy 2019年03月16日 846次浏览

brew介绍

brew是mac电脑的包管理软件,如果你使用过Centos的yum,ubuntu的apt-get就应该很容易明白brew是什么了,使用brew可以方便的管理mac电脑的软件,特别方便,比如安装wget 只需要在终端中执行brew install wget

安装brew

在mac终端执行如下命令即可安装brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/sbin
/usr/local/Caskroom
/usr/local/Frameworks

Press RETURN to continue or any other key to abort

修改brew的源

由于国内网络环境的问题,brew更新软件包是非常慢的,一般都会修改软件包的源,让brew从国内的地址更新,这样更新速度就快的多了,brew的源分两块,git repo(位于GitHub)和二进制bottles(位于bintray),这两者在国内访问都不太顺畅。可以替换成国内的镜像,比如中科大的。

修改brew的git repo

修改为中科大的源

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

修改为清华的源

cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update

还原为brew默认源

cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

修改brew的二进制源

对于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 install xxxxx
brew安装软件的目录在 /usr/local/Cellar 并且会在/usr/local/bin/ 目录下面建一个软连接到安装的应用文件。比如:/usr/local/bin/wget -> ../Cellar/wget/1.20.1_4/bin/wget

brew install wget
==> Installing dependencies for wget: gettext, libunistring and libidn2
==> Installing wget dependency: gettext
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/gettext-0.19.8.1.
######################################################################## 100.0%
==> Pouring gettext-0.19.8.1.mojave.bottle.tar.gz
==> Caveats
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo \'export PATH="/usr/local/opt/gettext/bin:$PATH"\' >> ~/.zshrc

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> Summary

参考连接

https://brew.sh/