Skip to content
Latchkey

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=1 and HOMEBREW_NO_INSTALL_CLEANUP=1.
  • Cache ~/Library/Caches/Homebrew with a key over your formula list or Brewfile.
  • Run brew install (or brew 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=Brewfile

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →