You have 2 free member-only stories left this month.

How To Automate Homebrew Installs on Your New Mac or Linux

You don’t need to install Homebrew packages one by one

Drawing of colorful structure on island
Pixel art with permission by © Waterflame.

[Update: 2021–06–30]

If you are programming on macOS, chances are you use Homebrew. Even if you are a Linux user, you may be using Homebrew. I install most of my apps and tools with Homebrew. On my 2017 macOS, I installed about 100 formulae and 30 casks with Homebrew.

This month, I got a new MacBook Pro (M1 chip) and I didn’t want to install all the apps and tools one by one. So I created Automate Brew Installer (Abi). Abi creates GitHub Gists from your Homebrew formulae and casks. It also installs Homebrew formulae (packages) and casks from these gist lists.

Table of Contents
· Prerequisite
· Homebrew’s Formula, Cask, and Tap
· Installing Abi
· Log Into GitHub
· Creating Gists
File name and description
A secret gist
· Edit Gist Lists
· Automate Brew Installation
Conclusion

Prerequisite

You need to have a GitHub account and some experience with a terminal.

Homebrew’s Formula, Cask, and Tap

Homebrew calls its package definition files “formulae.” Homebrew-Cask is an extension to install GUI applications. When you install Homebrew casks, you find them in your Applications directory. A Homebrew tap is a package created by a third party, like you and me.

Let’s get started using Abi.

Installing Abi

You can run the following on your terminal to install Abi:

brew tap shinokada/abi && brew install abi

Or using Awesome package manager:

awesome -i shinokada/abi

Log Into Github

When you install Abi, it will install Github CLI gh. After installing Abi, log into GitHub using gh on your terminal:

gh auth login

Follow the instructions to log into Github.

Creating Gists

Let’s create a Homebrew formula gist and a cask gist on your Mac:

abi leaves
Outputs from abi leaves. Image by the author.
Outputs from abi leaves. Image by the author.
Outputs from abi leaves. Image by the author.

This creates a Homebrew formula gist with the default file name and description. The default file name and descriptions are “my-brew-formula” and “My brew list.” It will open a browser to show your gist.

Let’s create a Homebrew cask gist with the default file name and description:

abi cask

The default file name and descriptions for a cask gist are “my-brew-cask-formula” and “My brew cask list.”

Outputs from abi cask. Image by the author.
Outputs from abi cask. Image by the author.
Outputs from abi cask. Image by the author.

File name and description

You can create a Homebrew gist with your description and file name using -d "description" -f file-name. Make sure that you have “cask” in the file name or description. Use quotes for your description since you will have spaces.

abi leaves -d "My brew list 2021-06-30" -f brew-list-mac-2017
abi cask -d "My brew cask list 2021-06-30" -f brew-cask-list-mac-2017

A public gist

You can create a public formula gist by using the -p flag:

abi leaves -p
# Or adding description and file name
abi leaves -p -d "My secret gist" -f brew-list-2017

Edit Gist Lists

You may wish to edit the generated gist lists. Go through the gist and remove or add new formulae.

If you want to add more Homebrew formulae, find them on this website. Be careful not to mix formulae and casks. Casks have --cask in their formulae.

Automate Brew Installation

Now on another Mac, let’s install formulae from your gist.

Install Abi:

brew tap shinokada/abi && brew install abi

Install Homebrew formulae from a gist. Using the install flag installs the formulae from the Gist URL:

abi install Your-Gist-URL

For example:

abi install https://gist.github.com/shinokada/136f21f96170fb8f0fb0691bfd45242b

This will install Homebrew formulae and taps (remember that taps are listed with formulae).

Let’s install the Homebrew casks from a gist. Using the installcask flag indicates installing cask formulae. Again, add your cask Gist URL:

abi installcask Your-Gist-URL

For example:

abi installcask https://gist.github.com/shinokada/32f0cc30fb48be090bf541ad387def47

When you need help:

abi -h

Find out if you have the latest Abi version:

abi -v

Better Programming

Advice for programmers.

Thanks to Cecilie Okada, Emile Okada, Elliot Gunn, and Anupam Chugh. 

Sign up for programming bytes

By Better Programming

A weekly newsletter sent every Friday with the best articles we published that week. Code tutorials, advice, career opportunities, and more! Take a look.

You'll need to sign in or create an account to receive this newsletter.

Shinichi Okada

Written by

Tools and tips for programmers. Math teacher, programmer, husband, father, Japanese. https://bit.ly/3nEaAfr.

Better Programming

Advice for programmers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Start a blog