---
title: 'Brewfile: a Gemfile, but for Homebrew'
teaser: Add a Brewfile to your project or laptop setup script.
tags: osx
author: Gabe Berke-Williams
published_on: 2014-01-20
---

[Bundler] users define dependencies for Ruby applications in a Gemfile
and install those dependencies by running `bundle install`.

[Homebrew] users on macOS can define system dependencies for their projects
with a `Brewfile`:

```bash
# Brewfile
brew "openssl"
# a comment
tap "homebrew/dupes"
```

The [`brew bundle`][brew-bundle] command is automatically installed the first
time it is used.  Simply [create a `Brewfile`][brew-bundle-usage] at the root
of your project's directory tree, and run `brew bundle` while in that
directory.

Note that Homebrew will treat lines that start with `#` as comments. To install
a package, use `brew`, and to tap a repository, use `tap`. So this:

```bash
brew "openssl"
# a comment
tap "homebrew/dupes"
```

is equivalent as these commands:

```sh
brew install openssl
brew tap homebrew/dupes
```

## Usage

I can think of a few places where a `Brewfile` would be welcome:

* In dotfiles, either yours or your company's.
* A [setup script] for your app (`bundle install && brew bundle`)
* A setup script for a new machine. I often forget to install one of them (like
  [rbenv-gem-rehash]).

It's a neat encapsulation for non-programming-language dependencies like
`phantomjs`.

## What's next

If you found this useful, I recommend checking out the [source][brew-bundle]
of the `brew bundle` command. For more Homebrew tricks, read through our
[macOS-related posts].

[Bundler]: http://bundler.io/
[Homebrew]: http://brew.sh/
[setup script]: https://thoughtbot.com/blog/bin-setup
[rbenv-gem-rehash]: https://github.com/sstephenson/rbenv-gem-rehash
[brew-bundle]: https://github.com/Homebrew/homebrew-bundle
[brew-bundle-usage]: https://github.com/Homebrew/homebrew-bundle#usage
[macOS-related posts]: https://thoughtbot.com/blog/tags/osx
