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=~/BrewfileThis 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=~/BrewfileHomebrew adds the taps and installs every formula and cask in the list.
Check and tidy up
brew bundle check --file=~/Brewfilebrew bundle cleanup --file=~/Brewfilecheck 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.