Using Brewfile to Share Homebrew Config

Using Brewfile to Share Homebrew Config

Table of Contents

Introduction

I am making use of a variation of dotfiles to manage my configuration files. One of the tools I use is Homebrew , a package manager for macOS. I wanted to find a way to share my Homebrew configuration with others. I found that I could use a Brewfile to do this.

What is Brewfile?

Brewfile manages packages installed by Homebrew. It also supports brew-cask and other Homebrew subcommand installers.

What are dotfiles?

Dotfiles are hidden files in your home directory that typically contain configuration settings for applications. They are called dotfiles because their filenames begin with a dot (period). I have been using a version control process to track multiple dotfiles and share them between different machines. Homebrew config isn’t exposed by default in a dotfile and so I have inconsistent Homebrew configurations across my machines.

Install brewfile

Run the following command to install brewfile:

brew install rcmdnk/file/brew-file

Then add the following lines to your .bashrc or .zshrc file (or both):

if [ -f $(brew --prefix)/etc/brew-wrap ];then
  source $(brew --prefix)/etc/brew-wrap
fi

Export the Brewfile

Reload your shell and initialise brewfile:

brew init

This will review the installed packages, then output a brewfile to the default location of ~/.config/brewfile/Brewfile. With my Hombrew config stored as a dotfile, I can now commit it to my dotfiles repository and share with my other machines.

Update other machines

With the brewfile committed to my dotfiles repository, and available on my other machine, I can load the brewfile by running the following command:

brew file install

Review the brewfile

If you want to review the brewfile, you can run the following command:

brew file cat

# tap repositories and their packages

tap homebrew/core
brew aom
brew azure-cli
brew brotli
brew c-ares
brew ca-certificates
brew cairo
brew cascadia
brew cask
... ## clipped for brevity

Conclusion

I have found Brewfile to be a useful tool for producing a dotfile, which allows me to share my Homebrew configuration between machines. It is a simple process to export the brewfile and commit it to my dotfiles repository. I can then load the brewfile on my other machines and have a consistent Homebrew configuration across all of them.

References

#mtfbwy



Recent Posts

Hugo Live Reload Keeps Reloading

Hugo Live Reload Keeps Reloading

  • 2024-05-18
  • 3 minutes to read

I have run into an issue from time to time where Hugo's live reload feature keeps reloading the page. This is how I fixed it.

Read More
First Steps with Mermaid in Vscode

First Steps with Mermaid in Vscode

  • 2024-05-17
  • 7 minutes to read

My blog theme supports mermaid, a visual diagram syntax, so I wanted to try it out in vscode.

Read More
T-SQL Tuesday #174 My favourite job interview question

T-SQL Tuesday #174 My favourite job interview question

  • 2024-05-14
  • 4 minutes to read

This is my 12th contribution to TSQL Tuesday, the data community blog party. Have a read, and why not join in next time!

Read More