共计 1717 个字符,预计需要花费 5 分钟才能阅读完成。
1. 如何正确设置 HTTP/HTTPS 代理
设置了 brew 通过 socks5 的代理后,会发现 pip 其实是不支持 socks5 的,只能通过 http/https。
首先获取端口
- 点击状态栏的小火箭
- HTTP Proxy Preference
- 获取 HTTP 的端口号(我是 1087)
将以下内容添加进.bash_profile(bash 用户)/.zshrc(zsh 用户)并保存
# 设置 HTTP/HTTPS Proxy | |
export http_proxy="http://127.0.0.1:1087"; | |
export https_proxy="http://127.0.0.1:1087"; |
保存,进入 shell,以 zsh 为例
# 更新配置 | |
source .zshrc | |
#验证 | |
brew update | |
pip install --upgrade pip |
2. 如何正确为 brew 换源
设置全局代理或者换源都有各自的优缺点,如果你想换源,那么尝试下面的步骤,要注意的是, 换源和设置代理只能选其一 ,不然结果是一样的。
按照一般方法更换中科大源后,执行 brew update 还是巨慢,后来发现是 cask 仍然接在 github 上,所以要把 cask 一起换了。要注意的是,Caskroom 的 Git 地址在 2018 年 5 月 25 日从 https://github.com/caskroom/h… 迁移到了 https://github.com/Homebrew/h…。
更换中科大源:
# 替换 brew.git: | |
cd "$(brew --repo)" | |
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git | |
# 替换 homebrew-core.git: | |
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" | |
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git | |
# 替换 homebrew-cask.git: | |
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask | |
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git | |
# 替换 homebrew-bottles: | |
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc | |
source ~/.bash_profile |
重置官方源:
# 重置 brew.git: | |
cd "$(brew --repo)" | |
git remote set-url origin https://github.com/Homebrew/brew.git | |
#重置 homebrew-core.git: | |
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" | |
git remote set-url origin https://github.com/Homebrew/homebrew-core.git | |
#重置 homebrew-cask.git:cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask | |
git remote set-url origin https://github.com/Homebrew/homebrew-cask | |
#Caskroom 的 Git 地址在 2018 年 5 月 25 日从 https://github.com/caskroom/homebrew-cask 迁移到了 https://github.com/Homebrew/homebrew-cask | |
#最后注释掉 /.bash_profile 里的 homebrew-bottles 并保存,以 bash 为例 | |
cd ~ | |
open .bash_profile | |
#更新.bash_profile | |
source .bash_profile | |
#验证 | |
brew update |
正文完