In this post, I will show how to publish any CLI app to Homebrew. The formula will install the binaries from GitHub Releases for a completely free setup.I had quite a lot of problem figuring out how to do this, so I hope this post will help you. We will create a formula for our app and publish it to our own Homebrew Tap.
Setting up a tap
The first thing we need to do is to create a tap.
A tap is a repository that contains formula.
The formula is the actual CLI program and our tap can contain many Formulas.
We can either publish our own tap our get our Formula
into the official Homebrew repository which can take some time.
In this post we will create our own tap.
The tap will be a GitHub repository that contains our Formula.
To create a tap, run:
After this we will get a message that contains the path to our tap. Like this:
We can now navigate to this folder and create a new Formula.
In your tap folder you should have the following structure:
Creating a Formula
For this step you need to have a compiled binary of your CLI app published on GitHub Releases. For a guide how to do this in Rust, see my post Publish a Rust CLI App with GitHub Actions. A simliar setup can be used for other languages.
We will now create a new Formula in the Formula folder.
The filename should be kebab-case and end with .rb. For example dns-cli-tools.rb.
Users will later install your CLI app by running:
We now want to define how to install the CLI app.
For this step it is important that you have the binaries published on GitHub Releases.
Below I will refer to your github url as <YOUR_GITHUB_URL>.
Replace this with the URL to your github repository. For example https://github.com/Hugo-Persson/dns-cli-tools
Getting the SHA256 hash
We need to get the SHA256 hash for the binaries. This is to ensure that the binaries are not tampered with. We can get the SHA256 hash by running:
For my CLI app, I automated this with a simple bash script like this: