Mac 上重新安装homebrew

6,786 阅读1分钟

介绍

最近mac电脑brew出现了问题,打算重新安装,在安装前mac系统升级到了版本12.1.下面我记录下重新安装的过程。

卸载

我们使用官网提供的卸载命令:

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

运行出现如下错误:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

通过上网搜索我们会看到stack overflow上的解决方案,试了下不怎么有效。

443端口连接拒绝一般是因为墙的原因,如果可科学上网(Virtual Private Network),在命令行运行如下命令:

# 7890 和 789 需要换成你自己的端口
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:789

再次执行上面的卸载命令便可正常执行,此方法当前可用,不便之处在于执行上面命令后,终端当前session的所有命令都是翻墙的,解决办法:关闭当前终端会话

更推荐推荐的是使用 proxychains-ng 来更方便的代理命令行

安装

通过以下命令安装:

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

安装完成后执行brew update的时候又遇到下面的问题:

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Homebrew/Library/Taps/jonj/homebrew-old-openssl failed!
fatal: 'origin/master' is not a commit and a branch 'master' cannot be created from it
fatal: invalid upstream 'origin/master'

我们继续去stack overflow去看看是不是有答案,我们查到解决方案

我执行了如下命令:

brew untap jonj/homebrew-old-openssl

再次执行brew update则不会再出现错误。

总结

如果你也遇到homebrew的安装或者卸载的问题希望能帮到大家

参考资料

zhuanlan.zhihu.com/p/115450863

stackoverflow.com/questions/2…

zhuanlan.zhihu.com/p/124199138

stackoverflow.com/questions/6…