How to have your own
private Brew package

Published May 13, 2023 by Ricard Bejarano

So you have a private Git repository. Doesn’t matter if it’s in GitHub, GitLab, or some dusty server you have in a shelf.

And you want to install whatever’s in it using Homebrew, but you don’t want to make your repository public.

Well, here’s how!

1. Add a formula to your repository

When you do brew install foo, “foo” is a formula.
A formula is a set of instructions for installing a package.

You can create a formula with a Ruby file like this:

# foo.rb                              # CHANGEME: rename to "[formula].rb", where "[formula]" is "brew install [formula]"
class Foo < Formula                   # CHANGEME: rename "Foo" to "[formula]", in CamelCase
  desc "A foo-rmula, haha... sorry"   # CHANGEME: you probably want something useful here, not my stupid jokes
  homepage "https://example.com/foo"  # CHANGEME

  url "git@example.com:path/to/repo.git", :using => :git, :tag => "v1.0.0"  # CHANGEME

  def install
    bin.install "foo"  # CHANGEME
  end

  test do
    system "true"  # CHANGEME
  end
end

Here’s a reference with all the arguments explained in detail.

Put this file in the root of your private Git repository.

2. Add your repository as a tap

A tap is an external repository, a place full of formulas. When you added your formula to your Git repository, it became a tap.

You can point Homebrew to your private tap like:

$ brew tap example/tap git@example.com:path/to/repo.git

Here’s where the first bit of magic happens.

We’re telling brew to install your tap at git@.../repo.git. This means, it’ll use git to pull your repository, to then look for formulas.

Therefore, you must have access to your repository, otherwise it’ll fail. In other words, if you can git clone a repo, you can use it as a tap.

3. Install your formula

Now that we’ve added your tap, you can install your formula:

$ brew install foo

And here’s where the second bit of magic happens.

When you do this, brew will download your package from the url in our formula file above. In our formula, we told brew to use git again, to pull git@.../repo.git at tag v1.0.0.

Thanks for dropping by!

Did you find what you were looking for?
Let me know if you didn't.

Have a great day!