If you have encountered the “brew update” problem where you see an error message like the following:

1
fatal: unable to access 'https://github.com/caskroom/homebrew-cask/': Failed to connect to github.com port 443 after 75018 ms: Couldn't connect to serve

summarize:

  1. The error message you received indicates that Homebrew was not able to connect to the GitHub server. This can be caused by a number of factors, including network connectivity issues or server problems.

  2. The first method provided involves modifying your Homebrew settings to use a mirror hosted by Tsinghua University in China. This mirror is typically faster and more reliable for users in mainland China.

  3. To modify your Homebrew settings, you need to open your .bashrc or .zshrc file (depending on which shell you are using) and add the environment variables listed in the article. You can do this using a text editor or by running a command like nano ~/.bashrc.

  4. Once you’ve added the environment variables, you need to activate your .bashrc or .zshrc file by running the source command as shown in the article. This will ensure that the new settings take effect.

  5. The -v option used in the brew update -v command stands for “verbose” and will show more detailed output as Homebrew updates. This can be helpful for troubleshooting or diagnosing problems.

  6. In general, it’s a good idea to keep your Homebrew installation up to date to ensure that you have access to the latest versions of software packages. You can do this by running the brew update command periodically.

Recently, there have been frequent issues with not being able to connect to GitHub when using update brew. Additionally, I have been using ChatGPT recently, so I tried to ask and resolved the issue. If you are in mainland China like me, you can refer to the following methods to modify Homebrew’s parameters:

step one

Open your .bashrc or .zshrc file and add the following environment variables:

1
2
3
4
5
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"

This will replace some of Homebrew’s default settings with the ones from the Tsinghua University mirror.

step two

Activate your .bashrc or .zshrc file by running:

1
source ~/.bashrc

or

1
source ~/.zshrc

Once you’ve completed these steps, you can run the following command to update Homebrew:

1
brew update -v

EOF
Enjoy
I, simon love this world ❤️