Homebrew更新记

Mac下安装软件,最方便的莫过于Homebrew了。之前挺长一段时间,用brew install安装软件一直卡在

Updating Homebrew

不动。后来一查原因,发现是brew源https://github.com/Homebrew/homebrew/已经弃用了,不再更新。

办法是重置brew源,因为Homebrew是依赖于Github的,所以重置brew源的方法也很简单

1
2
3
4
5
6
7
// 重置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

网上有推荐用国内镜像来替换brew.git源以及homebrew-core.git源,从而达到加速的目的,我觉得比较适合不想折腾的人。

重置完成后,如果忘了之前重置的git远程地址,可以使用命令

1
git remote -v

来查看远程地址。

接下来就是使用命令brew update来更新brew了。因为国内特殊的环境,Github只能看,不能摸(下载),原因你懂的。

怎么解决?使用代理。Mac设置代理很简单,

1
export ALL_PROXY=socks://127.0.0.1:1080

这样设置后,普通的http/https/socks协议都会通过我本地的1080端口进行转发。

另外还要设置git走代理

1
2
3
4
5
6
7
8
9
10
11
12
13
// 设置全局代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080

// 取消全局代理
git config --global --unset http.proxy
git config --global --unset https.proxy

// 查看当前用户(global)配置
git config --global --list

// 查看当前仓库配置信息
git config --local --list

设置完毕后,执行brewe update,发现报错

1
2
3
4
5
6
7
> fatal: unable to access 'https://github.com/Homebrew/brew/': SSLRead() return error -9806
> fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': SSLRead() return error -9806
> fatal: unable to access 'https://github.com/caskroom/homebrew-cask/': SSLRead() return error -9806
> Error: Fetching /usr/local/Homebrew failed!
> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
> Fetching /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask failed!
>

或者是

error: RPC failed; transfer closed with outstanding read data remaining

这个问题困扰了我好久,后来我发现其实是代理问题,因为代理不稳定,导致Homebrew更新失败。换一个稳定一点地代理就行了。

总结

之前更新brew的时候走了不少弯路,也停滞了很久,没想到还是代理的问题。所以,推荐用国内的brew源还是挺方便的,不折腾。

avatar

chilihotpot

You Are The JavaScript In My HTML