fren

Syncing Your Homebrew Apps Between Two Macs

3 min read
Syncing Your Homebrew Apps Between Two Macs
🤖 AI-generated summary
* Homebrew has a built-in tool for this: brew bundle * A Brewfile versioned in Git or synced via Syncthing, and you're done

I have two Macs. One for work at the office, one personal at home. And I kept finding myself installing something on one machine only to realize it was missing on the other.

Homebrew has a built-in tool for this. No custom script or third-party app needed.

What is a Brewfile

brew bundle generates a Brewfile that lists everything installed via Homebrew on your machine: formulas (CLI tools), casks (GUI apps), taps (third-party repos), and even Mac App Store apps if you use mas.

It looks like this:

tap "homebrew/bundle"
brew "git"
brew "node"
brew "ffmpeg"
cask "raycast"
cask "iterm2"
cask "visual-studio-code"
mas "Things 3", id: 904280696

A plain text file. Readable. Versionable. Exactly what you want.

Exporting your Mac’s state

On your main Mac, one command:

brew bundle dump --file=~/Brewfile --describe --force

The --describe flag adds a comment next to each line so you can tell what’s what. The --force flag overwrites the file if it already exists.

If you also want your Mac App Store apps, install mas first:

brew install mas

Installing on the other Mac

Copy the Brewfile to your second Mac (Git, Syncthing, AirDrop, whatever) and run:

brew bundle --file=~/Brewfile

Homebrew installs everything that’s missing. What’s already there is skipped.

Keeping it in sync

The simplest approach: put the Brewfile in a Git repo. Commit when you add or remove something, pull on the other Mac, run brew bundle, done.

If you already have Syncthing or a NAS with sync set up, you can also drop the file in a shared folder. The Brewfile propagates automatically.

Useful everyday commands

brew bundle check tells you whether your Mac is in sync with the Brewfile. Exit 0 = all good.

brew bundle cleanup lists what’s installed on your machine but absent from the Brewfile. Useful for spotting things you installed by hand and forgot to add. With --force, it uninstalls them directly.

To regenerate the Brewfile after changes, I just re-run brew bundle dump --force. It’s idempotent.

New Mac: reinstall everything in 5 minutes

This is where the Brewfile really shines. You’ve just unboxed a new Mac, you open Terminal, and:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
git clone https://github.com/ton-user/dotfiles.git ~/dotfiles
brew bundle --file=~/dotfiles/Brewfile

Three commands. Homebrew installs, your repo clones, and all your apps install themselves. Go make a coffee, come back, it’s ready.

I changed my work Mac last year. Without the Brewfile, I’d have spent half a day tracking down and reinstalling my apps one by one . Instead, it was done in 10 minutes.

What I actually do

My Brewfile lives in my dotfiles repo, alongside my Zsh config and aliases. With every brew install or brew install --cask, I regenerate the Brewfile and commit. It’s become a reflex.

The day a Mac dies on me or Apple releases a machine I can’t resist, I know I’m three commands away from having my full environment back. Not glamorous, but it works.

Feel free to reach out if you’d like to react to this article.

Got a reaction to this article?

Feel free to reach out if you'd like to react to this article.

Me soutenir