How to Cache Homebrew in GitHub Actions
Cache Homebrew download cache and disable auto-update so brew installs reuse bottles instead of refetching them each run.
Cache ~/Library/Caches/Homebrew keyed on your Brewfile or formula list, and set HOMEBREW_NO_AUTO_UPDATE=1 so brew does not spend a minute updating itself before every install.
Steps
- Set
HOMEBREW_NO_AUTO_UPDATE=1andHOMEBREW_NO_INSTALL_CLEANUP=1. - Cache
~/Library/Caches/Homebrewwith a key over your formula list or Brewfile. - Run
brew install(orbrew bundle) after the restore.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: macos-latest
env:
HOMEBREW_NO_AUTO_UPDATE: '1'
HOMEBREW_NO_INSTALL_CLEANUP: '1'
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/Library/Caches/Homebrew
key: brew-${{ runner.os }}-${{ hashFiles('Brewfile') }}
restore-keys: brew-${{ runner.os }}-
- run: brew bundle --file=BrewfileGotchas
- The cache stores downloaded bottles, not installed formulae; brew still links them, which is fast.
- Auto-update can rewrite the whole tap and invalidate timing; disabling it makes runs more deterministic.
Related guides
How to Install a Tool With Homebrew in GitHub ActionsInstall a CLI tool on a GitHub Actions macOS runner with brew install, pinning auto-update off so the step st…
How to Cache CocoaPods in GitHub ActionsCache the CocoaPods Pods directory and spec repo on a GitHub Actions macOS runner with actions/cache keyed on…