How to resolve the 443 Error when using homebrew?

270 阅读1分钟

Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn't include with macOS. But sometimes we would encounter some 403 errors when we run brew install or brew update command.

➜  Homebrew git:(stable) brew update -v
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!
Updating /usr/local/Homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.
Switched to and reset branch 'stable'
Current branch stable is up to date.

Error reason

This error is caused by poor network conditions linked to the original homebrew source.

How to solve this error?

Using alternative source.

Fortunately, there are several reliable domestic homebrew mirror sources such as ustc, aliyun, tsinghua which respective domains are https://mirrors.ustc.edu.cn, https://mirrors.aliyun.com, https://mirrors.tuna.tsinghua.edu.cn. So we just need to change all the remote urls of the related homebrew repos such as homebrew, homebrew-core, homebrew-cask.

How to change the remote url of the related repos?

git -C "$(brew --repo)" remote set-url origin path/to/mirror-domain/brew.git
git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-core" remote set-url origin path/to/mirror-domain/homebrew-core.git
git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" remote set-url origin path/to/mirror-domain/homebrew-cask.git

Using Proxy

export https_proxy=protocol://proxy_host:port