How to easily migrate your Brew packages in macOS

Recently I decided to do a clean install on my personal Mac at the same time and start optimizing my dev setup and overall productivity. The first step towards this goal was to automate installing all the packages and apps I use daily. I have been using Homebrew to manage my macOS dependencies for a few years now and recently I discovered the awesomeness of Brewfiles to export and move dependencies to your new Mac and/or to track it in version control.

This very short guide assumes that you already are using Brew to manage macOS packages. If not, you can create a Brewfile in your home directory and use a text editor to list the packages that you wish to install. Then go directly to step 2.

1. Dump package list into a Brewfile

brew bundle dump

This will generate a file in your current directory. You should open it and remove any packages that you don’t want to install in your new machine.

2. Install the Brewfile packages

Transfer your Brewfile to your new Mac be sure to first install brew. I suggest you track this file in a private repo so is easier to track and move around. To install your packages just run;

brew bundle install

This command will look for a Brewfile in your home directory ~/Brewfile and attempt to install its content. Be mindful that this will take a while, depending on your list of packages.
Now enjoy your freshly-installed Mac!