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.

Brewfiles

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:

tap 'caskroom/cask'
tap 'homebrew/bundle'
tap 'homebrew/core'
tap 'homebrew/dupes'
tap 'homebrew/php'
tap 'homebrew/services'
tap 'homebrew/versions'
brew 'android-platform-tools'
brew 'autoconf'
brew 'boost'
brew 'readline'
brew 'calc'
brew 'cscope'
...

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:

cd ~/Dropbox
brew bundle

Voilá! Homebrew starts reinstalling all packages.

A terminal window with the output of the 'brew bundle' command to restore the Homebrew configuration. Installing a number of packages using a Brewfile.

Creating a custom Brewfile

The Brewfile syntax is easy. Each line is a command that gets executed. First, create an empty Brewfile:

touch Brewfile

Then – as an example – add a tap, a two brew packages and a cask respectively:

ap 'homebrew/php'
brew 'homebrew/php/php71', args: ['with-imap']
brew 'shpotify'
cask 'spotify

Isn’t it nice?

Sponsored content