How to back up and restore your Homebrew setup with a Brewfile

Updated · by Nico Wickersheim

A Brewfile is a plain text list of your taps, formulae and casks. With it, setting up a new Mac takes one command instead of an afternoon of remembering what you had installed.

Export your setup

brew bundle dump --file=~/Brewfile

This writes everything you have installed into ~/Brewfile. Add --force to overwrite an existing file and --describe to add a short description above each entry. Without --file, the Brewfile is created in the current folder.

What's inside

tap "owner/tools"
brew "git"
brew "node"
cask "firefox"
cask "visual-studio-code"

Each line is one package. You can edit the file by hand, remove things you don't want on the next Mac, or keep it in your dotfiles repository.

Restore on a new Mac

Install Homebrew from brew.sh, copy your Brewfile over and run:

brew bundle install --file=~/Brewfile

Homebrew adds the taps and installs every formula and cask in the list.

Check and tidy up

brew bundle check --file=~/Brewfilebrew bundle cleanup --file=~/Brewfile

check tells you whether anything from the Brewfile is missing. cleanup lists installed packages that aren't in the Brewfile. Add --force to actually uninstall them.

Before exporting, it's a good moment to remove packages you no longer use.

Prefer clicking over typing?

WailBrew is a free, open-source Homebrew GUI for macOS. It runs the same brew commands for you, behind a fast native interface.

Download WailBrew

or brew install --cask wailbrew

More Homebrew guides