解决【Homebrew installation on Mac OS X Failed to connect to raw.githubusercontent.com port 443】错误

问题现象:

Mac上安装Homebrew 时

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

报以下错误

curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 18 ms: Couldn't connect to server

 

问题原因:

DNS 解析过程无法通过域名取得正确的IP地址。可以通过修改/etc/hosts文件可解决该问题。

具体而言:

打开 https://www.ipaddress.com/ 输入访问不了的域名,获得对应的IP。

 

问题解决:

使用vim /etc/hosts命令打开不能访问的机器的hosts文件,添加如下内容:

199.232.68.133 raw.githubusercontent.com
199.232.68.133 user-images.githubusercontent.com
199.232.68.133 avatars2.githubusercontent.com
199.232.68.133 avatars1.githubusercontent.com

注:上面内容中199.232.68.133是raw.githubusercontent.com所在的服务器IP(通过 https://www.ipaddress.com/ 获知)。

保存后,再次使用即可正常。

posted @ 2025-04-05 19:11  葫芦杯  阅读(333)  评论(0)    收藏  举报