This article is transcribed by 简悦 SimpRead, original at juejin.cn
Summary of “Pitfalls” and “Fixes” Experiences in Using Homebrew!
- Homebrew Auto-Update Issue
Problem: When running brew install or upgrade, Homebrew forcibly runs update, which takes time.
Solutions (ranked by recommendation):
-
Export environment variable (recommended): Add to ~/.zshrc or ~/.bashrc:
bash
export HOMEBREW_NO_AUTO_UPDATE=1Globally disable auto-update; need to manually run brew update to check for updates.
-
Use alias: Add to ~/.zshrc or ~/.bashrc:
bash
alias brew="HOMEBREW_NO_AUTO_UPDATE=1 brew"Same effect as above, but only effective for brew command.
-
Disable once: Temporarily disable auto-update:
bash
HOMEBREW_NO_AUTO_UPDATE=1 brew install <formula> -
Use Homebrew/aliases:
bash
brew alias install_no_autoupdate='!HOMEBREW_NO_AUTO_UPDATE=1 brew install'Then replace brew install with brew install_no_autoupdate.
Supplement:
- After disabling auto-update, periodically run brew update manually to get the latest formulas.
- To temporarily enable auto-update, run unset HOMEBREW_NO_AUTO_UPDATE.
- Confusion Between Cask and App Store Apps
Problem: Both Cask and App Store install apps into /Applications, causing:
- Unable to distinguish source of installation.
- The same app might be overwritten.
Solution:
-
Set Cask installation path: Add to ~/.zshrc or ~/.bashrc:
bash
export HOMEBREW_CASK_OPTS="--appdir=~/Applications/_"Cask apps will be installed into ~/Applications/_/, separated from /Applications.
Author’s app management suggestions:
- App Store: Install to /Applications.
- Cask: Install to ~/Applications/_/.
- Cracked apps: Install to ~/Applications/#/.
- JetBrains IDE: Manage via JetBrains Toolbox (Toolbox itself is installed via Cask).
- Open source / free apps: Install to ~/Applications.
Supplement:
-
Ensure ~/Applications/_ and ~/Applications/# directories exist; create them manually if needed:
bash
mkdir -p ~/Applications/_ ~/Applications/# -
To avoid permission issues, check and adjust directory permissions:
bash
chmod -R u+rwX ~/Applications
- Bulk Update Issue for Cask
Problem: Old scripts no longer work; need a more efficient way to update Cask apps.
Solution:
-
Install cask-upgrade:
bash
brew tap buo/cask-upgrade -
Use commands:
-
Update all updatable apps:
bash
brew cu -
Update specific app:
bash
brew cu <app> -
Common options:
- -a: Include auto-updated apps.
- -f: Force update apps with version marked as latest.
- -y: Auto-confirm all update prompts.
-
Supplement:
-
Project address: buo/homebrew-cask-upgrade.
-
Before running brew cu, it is recommended to run brew update to ensure the Cask repo is up to date.
-
If update fails, try updating apps individually and check logs:
bash
brew cu <app> --verbose
- Slow Homebrew Speeds Due to Domestic Network
Problem: brew update and brew install are slow due to network issues.
Solution:
-
Change source (recommended):
-
Refer to Tsinghua mirror guide:
-
brew update slow: change Homebrew core repo source.
-
brew install slow: change Homebrew Bottles source.
-
Configuration steps (example using Tsinghua source):
bash
# Change core repo git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git git -C "$(brew --repo homebrew/cask)" remote unstoppable https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git # Change Bottles source echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc source ~/.zshrc -
Tsinghua source address: mirrors.tuna.tsinghua.edu.cn.
-
-
Other optional sources: University of Science and Technology of China, Alibaba Cloud, etc.
-
-
Proxy:
-
Set proxy (replace with your own proxy address and port):
bash
export all_proxy=socks5://<host>:<port> -
Suitable for users with stable proxy, generally faster.
-
Supplement:
-
The first brew update after changing source may be slow, but subsequent runs improve significantly.
-
If a mirror becomes invalid, switch back to official source:
bash
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git -
Proxy settings may affect other tools; you can unset after use:
bash
unset all_proxy
- SHA256/Checksum Mismatch Problem
Problem:
- Error: SHA256 mismatch (brew) or Error: Checksum mismatch (cask), due to mismatch between repo checksum and actual file.
Solutions:
-
Clear cache (try this first):
bash
rm -rf ~/Library/Caches/Homebrew brew install <formula/app>Applies when distributor modifies files without updating version number.
-
Manually modify checksum (if clearing cache doesn’t help):
-
Brew:
-
Edit formula file:
bash
nano /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/<formula>.rb -
Replace sha256 value with actual file checksum (can get via shasum -a 256).
-
-
Cask:
-
Edit Cask file:
bash
nano /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/<app>.rb -
Update sha256 value.
-
-
After saving, rerun brew install or brew cask install.
-
-
Notes:
-
Disable auto-update to prevent modifications from being overwritten:
bash
export HOMEBREW_NO_AUTO_UPDATE=1 -
Keep the editor, undo changes after successful install (to avoid Git conflicts).
-
Restore repos if conflict occurs:
bash
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core git reset --hard cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask git reset --hard
-