赞
踩
使用 brew install 时会触发 brew update,而update阶段主要是进行homebrew-cask 和 homebrew-core 及一些其他相关依赖的更新,这些依赖都托管在GitHub,由于国内网络访问GitHub本身就比较慢,做大文件下载的速度可想而知会更慢。
使用brew update –verbose观察update过程:
# 执行命令
brew update --verbose
可以发现在从 GitHub fetch 资源时是最罪恶根源。
目前国内比较好用的brew源有很多,比较推荐使用清华大学开源软件镜像站的,以下是详细配置
# brew 程序本身,Homebrew/Linuxbrew 相同
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 以下针对 mac OS 系统上的 Homebrew
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 以下这两个命令行可以不执行,不影响最终结果
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
# 以下针对 Linux 系统上的 Linuxbrew
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git
配置完成后,可以到对应的目录下查看git remote配置,如:
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote -v
看到显示为如下的结果说明已经配置成功:
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (fetch)
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (push)
临时替换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
永久替换
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
至此,已经完成了brew源的切换,可以运行brew update 测试是否正常。
另外,与上文无关的问题:
自己在 ~/.bashrc中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bashrc
发现zsh加载的是 ~/.zshrc文件,而 ‘.zshrc’ 文件中并没有定义任务环境变量。
解决办法:
在~/.zshrc文件最后,增加一行:
source ~/.bashrc
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。