Homebrew is a popular package manager for MacOS. It provides easy access to thousands of programs and applications. It is developed and maintained by an open-source community on Github. Use Homebrew bundle to backup and restore your Homebrew configuration.
If you haven’t installed it yet, go take a look quick on brew.sh or just install it by running the following command in the MacOS terminal.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The installation should succeed without problems. Installing some nice tools is also easy:
brew install htop
To install a better alternative to the standard process viewer top.
This is where the magic happens. If you ever used npm, bower or another package-/assetsmanager you might be using dependency files that list a number of packages or assets that are to be installed. Brewfiles do about the same but then for your Homebrew configuration.
Let’s get started quickly! Install the Homebrew tap:
brew tap Homebrew/bundle
Dumping all of your Homebrew packages at once
Run the following command to create a text file named Brewfile with all Homebrew packaged installed on your system:
brew bundle dump
This creates a file with a lot of entries:
Keep this file safe in your cloud filestorage like Dropbox or e-mail.
mv Brewfile ~/Dropbox
Restore your configuration
Change your working directory to the folder containing the Brewfile. Then, to install/restore all items in the file, run:
Voilá! Homebrew starts reinstalling all packages.
Creating a custom Brewfile
The Brewfile syntax is easy. Each line is a command that gets executed. First, create an empty Brewfile:
Then – as an example – add a tap, a two brew packages and a cask respectively:
brew 'homebrew/php/php71', args: ['with-imap']
Isn’t it nice?