Homebrew作为MacOS系统的管理器方便了软件安装及更新,但是使用过程中会遇到下载特别慢,brew update无反应等问题,这是因为资源在外网上,需通过更改源来改为国内的镜像地址,提高下载速度。
目前国内流行的镜像源有两个:清华源 和 中科大源,更改的方法是相同的,以下为详细步骤:
- 更换源需重置三个地方:
- brew.git
- homebrew-core.git
- homebrew-bottles
更换为清华源/中科大源
Step1. 重置brew.git
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
#清华源:
#$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
#中科大源:
#git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
Step2. 重置homebrew-core.git核心软件仓库
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
#清华源:
#$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
#中科大源:
#git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
Step3. 重置homebrew-cask.git源
$ cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
如果想换回原来的默认源,步骤如下:
重置默认源(github)
#‘’‘step1.重置brew.git’‘’
$ cd "$(brew --repo)"
#git remote -v #查看当前源
$ git remote set-url origin https://github.com/Homebrew/brew.git
#‘’‘step2.重置homebrew-core.git核心软件仓库’‘’
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://github.com/Homebrew/homebrew-core.git
#‘’‘Step3. 重置homebrew-cask.git源’‘’
$ cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
$ git remote set-url origin https://github.com/Homebrew/homebrew-cask
官网参考
brew install安装时报错
Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
原因
因为修改了用户名,之前brew是在admin下安装的,但是现在换了名字,就出现了这个问题. 其实就是文件的属组和用户无法辨识了
方案
sudo chown -R `whoami` /usr/local/Homebrew/
sudo chown -R $(whoami) $(brew --prefix)/*
sudo mkdir /usr/local/Frameworks
sudo chown -R `whoami` /usr/local/Frameworks/
pip下载推荐临时换源的方法
用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。
其中,比较常用的国内镜像包括:
- 阿里云 http://mirrors.aliyun.com/pypi/simple/
- 豆瓣 http://pypi.douban.com/simple/
- 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
- 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
- 华中科技大学 http://pypi.hustunique.com/
方法也很简单:pip install [formula] -I [url]
$ pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/