Brewmancy Mac OS
Perhaps the most-dreaded aspect of setting-up a new machine is the time spent on reinstalling apps and reapplying all of the customizations from the previous one. As my MacBook Pro is about to turn six, I had been looking for a way to automate this process. At least for the applications part, I recently found a good solution (that’s apparently been around for a while).
I just upgraded from Mac OS X 10.8 to 10.10 (Yosemite), and homebrew works fine after the upgrade. Either this problem was fixed, or there was something different about my OS upgrade compared to everyone else posting here. – Yitz Apr 8 '15 at 14:50. #showtooltip Keg Smash /cast Double Barrel /cast Keg Smash; This macro will automatically make use of the Double Barrel Honor Talent if you have it selected and cast it at the same time as your Keg Smash whenever the ability is off-cooldown. It will still work even if you do not have this Honor Talent selected and is useful if you would just like to benefit from its passive damage increase.
This post is about using a Brewfile
to migrate macOS packages and applications. If you’re already versed in the world of Homebrew and Homebrew Bundle, you might find it overly verbose. It’s written from a beginner’s perspective as up until recently I wasn’t too familiar with the concept myself.
Brewfile in a nutshell
A Brewfile
contains instructions on which packages, command-line utilities, and applications to install on a macOS system. Here’s a short snippet:
If I were to“run” this Brewfile
, it would install the Python and SQLite packages, then 1Password, Pages, and Drafts from the Mac App Store, and finally Carbon Copy Cloner, Dropbox, and VLC from Homebrew’s repository (which usually pulls them from their respective websites). All apps are installed in the Applications folder by default, but the ability to differentiate between App Store and non App Store applications is significant in my case.
This is already faster than doing any of these steps manually. What’s more, a Brewfile
can be generated automatically so you’d rarely need to write the lines above one-by-one.
Why Brewfile
Because the alternatives aren’t as good.
Cloning: Using the excellent Carbon Copy Cloner to clone my old HD to the new one would theoretically be the quickest way to get going, but after 6 years, I imagine there’s more than a little cruft in my system files, and recent changes to Apple’s hardware make this option even less attractive. There are also apps on my current machine that I actually don’t want to move over.
Time Machine and/or Migration Assistant: Migration Assistant hasn’t been known for its reliability lately, and Time Machine backups are not less problematic. Listing the advantages and drawbacks is beyond the scope of this post, but if you want to read more about the pros and cons of each migration strategy, Jason Snell does a good job on that.
Starting fresh: Nothing could go wrong, but a lot of time spent on configuration and installing apps.
A detour
To understand what a Brewfile
does and how it can fit in a migration strategy, it’s good to be familiar with the moving parts that make it useful. This is not an exhaustive overview, but rather an introduction into each.
Homebrew
In the beginning, there was Homebrew, a package manager created by Max Howell in 2009. After installing homebrew
, you can open the Terminal and install packages easily and quickly:
Behind the scenes, brew
is using what it calls a“formula” to install the ffmpeg
package. This formula is a piece of code that’s responsible for holding all the information required to install ffmpeg
: its name, version, URL to the source files that should be downloaded, and other packages that ffmpeg
needs in order to operate.
Homebrew not only makes it easy to install packages, but also to maintain them:
And to discover them:
homebrew
is very nice indeed. It’s lauded for its ease-of-use, documentation and helpful command-line feedback.
Homebrew Cask
homebrew-cask
is like homebrew
, but for macOS apps, fonts, plugins, and other non-open source software. If brew install [formula-name]
installs a package corresponding to that formula’s name, then brew cask install [cask-appname]
installs an application with that cask’s name:
By default, it places installed apps in the Mac’s Applications directory. You can search for casks the same way you search for formulae:
But where is firefox
coming from here? How does brew cask install firefox
know what to install?
A few pieces of information here:
firefox: 66.0.3
is the version we can expecthomebrew-cask
to install.From:
holds the URL where thecask
lives. If you inspect it you’ll see that somewhere in there is also the URL one would go to in the browser when installing Firefox the“regular” way. There’s no magic here.- Install options, like
Languages
. Runningbrew cask install firefox --language=it
will install Firefox in Italian.
Indeed, homebrew-cask
is very, very nice.
Mac App Store command line interface
There’s one more tool that we need to cover before Brewfile
: mas-cli
is a simple command line interface for the Mac App Store (MAS). It can’t install apps that you haven’t downloaded or purchased before, but it will allow you to upgrade those that you have installed, and download apps tied to your iCloud account:
mas-cli
may not seem terribly useful at first glance, but it was the missing piece in my migration strategy since it provides a way to capture all Mac Store apps currently installed:
Yes, mas-cli
is nifty.
So, brew install
, brew cask install
, and mas install
make things a lot faster. The next step is to find a way to automate the generation and execution of these commands.
Homebrew Bundle
homebrew-bundle
is an extension of homebrew
and is installed as soon as the command brew bundle
is first used. It’s the glue that brings everything together.
Run brew bundle dump
and Homebrew Bundle will generate a file called Brewfile
listing all of the installed brew packages, cask applications, and Mac App Store applications currently on the machine. If, on the other hand, you run brew bundle
from a folder that contains a Brewfile
, it will install everything listed in that file.
So, given a Brewfile
with the following content:
Running brew bundle
from the same directory where Brewfile
is located will install the above packages and applications.
Notice that the Brewfile
syntax differs from the commands you’d usually type in the Terminal. This table should help:
Terminal command | Brewfile |
---|---|
brew install [formulaName] | brew '[forumlaName]' |
brew cask install [caskName] | cask '[caskName]' |
mas install [identifier] | mas '[bundleIdentifier]', id: [identifier] |
I think you know where this is going by now: run brew bundle dump
on the current machine, copy the Brewfile
generated to the new one, run brew bundle
, and Homebrew will take it from there. If you have lots of apps and packages the process will take some time, but nowhere near the time (or effort) it would have taken to do manually.
A quick-guide on setting up a new macOS using a Brewfile
Here’s an abbreviated guide to set-up a new macOS with Homebrew Bundle. Unless otherwise stated, all commands below are to be typed in the macOS Terminal prompt.
The steps involved are:
- Installing dependencies on the current (source) macOS machine
- Installing Homebrew taps
- Generating a
Brewfile
- Migration
1. Installing dependencies on the source machine
Homebrew
Check if you already have Homebrew installed:
If Homebrew isn’t installed, the output should be something like brew: command not found
. Homebrew itself depends on the command line tools (CLT) for Xcode, installed like this:
You can then install Homebrew by pasting the following in your Terminal prompt:
If you do have Homebrew, and help
prints a long list of commands, it’s a good idea to run an update before proceeding:
Homebrew Cask
Comes with Homebrew, but it doesn’t hurt to make sure it’s there:
Homebrew Bundle
Will be installed as we run it (later).
Mac App Store CLI
The way to install this mas-cli
varies depending on the OS version. You can find simple instructions in the project’s Github repository, but if you have a recent version this should suffice:
2. Installing Homebrew taps
Think of taps
as additional sources brew
will look at when searching and installing formulae and casks. Here’s what I recommend if you’re following this tutorial:
3. Creating the Brewfile
Now that all of the of the dependencies are installed, let’s generate a Brewfile
:
Notice that Brewfile
may be missing non-MAS applications and packages that you haven’t installed with brew
or brew cask
. If you installed Firefox from Mozilla’s website, homebrew-bundle
doesn’t know about it. It’s easy enough to search for those and add them manually. And, it’s something you only have to do once since you’ll never ever again go to a website, find the install link, wait for the download to finish, and then drag the app icon to /Applications
.
A Brewfile
looks something like this:
If you’d like to omit some packages or otherwise change the Brewfile
that your target macOS will use, you can simply copy the file somewhere else and make your changes there.
I keep my Brewfile in a Github repository, but you can place it in Dropbox, Google Drive, or wherever.
One more change I do is placing all mas
directives before the cask
ones, so the App Store version of an app is preferred in case that app is mistakenly listed in both sections.
Brewmancy Mac Os Catalina
4. Migration
The only dependency needed on the new machine is Homebrew (see step 1). That’s because the Brewfile
pulled from the old setup already stages all others for installation.
Brewmancy Mac Os 11
Once Homebrew is installed and a Brewfile
is present, it’s as simple as running:
brew bundle
will look for a Brewfile
in the current directory, but you can also specify the path manually:
If you enjoyed this post, please consider donating to Homebrew.
Install Homebrew
Paste that in a macOS Terminal or Linux shell prompt.
The script explains what it will do and then pauses before it does it. Read about other installation options.
What Does Homebrew Do?
Homebrew installs the stuff you need that Apple (or your Linux system) didn’t.
Homebrew installs packages to their own directory and then symlinks their files into
/usr/local
.Homebrew won’t install files outside its prefix and you can place a Homebrew installation wherever you like.
It’s all Git and Ruby underneath, so hack away with the knowledge that you can easily revert your modifications and merge upstream updates.
Homebrew complements macOS (or your Linux system). Install your RubyGems with
gem
and their dependencies withbrew
.“To install, drag this icon…” no more. Homebrew Cask installs macOS apps, fonts and plugins and other non-open source software.
Donate to Homebrew
Homebrew Blog
Analytics Data
Homebrew was created by Max Howell. Website by Rémi Prévost, Mike McQuaid and Danielle Lalonde.