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

A Step-by-Step Guide To Create Homebrew Taps From GitHub Repos

Make your first Homebrew tap

A ruby file for Homebrew tap.
A ruby file for Homebrew tap. Image by Author.

Introduction

Homebrew is the missing package manager for macOS. It installs packages with a simple command like . Homebrew taps are third-party repositories. By creating a Homebrew tap formula, users can install and use your repo.

In this article, you will learn how to create a simple Homebrew tap. I used my gitstart for this article. Gitstart is a bash script to create a Git repo. It contains only one file.

Step 1: Git Tag

You need to add a Git tag to your repo:

$ git tag -a v0.0.2 -m "version 0.2.0"

Push your tag to the remote repo:

$ git push origin v0.2.0

Step 2. Create a New Release

On your GitHub repo, click Create a new release.

Releases section on GitHub repo. Image by Author.

In the Tag version, select the latest version and write the description of the release.

Creating a release. Image by Author.

Step 3. Run Brew Create

Find the source code (tar.gz) and copy the link address:

Copy Link Address from Source code (tar.gz). Image by Author.

Run and replace with your copied link.

For example:

$ brew create https://github.com/shinokada/gitstart/archive/refs/tags/0.2.0.tar.gz

It will show the content of the created file.

The output after running the brew create command. Image by Author.

If your default editor is VIM, quit the program by using .

A terminal view after quitting the editor. Image by Author.

Note the file path in outputs. In this case, the file path is:

"/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/gitstart.rb"

Step 4. Create a New GitHub Repo

Create a new GitHub repo. The naming should have “homebrew-” at the beginning.

For example, mine is .

In the new repo, copy or move the created file to your repo:

Line 2: Add a description of your repo.
Line 3: You must add a homepage.
Line 4: This should be auto-filled in. If not, use the copied link in the previous section.
Line 5: Replace the sha256 value with yours.
Line 6: Add your license. MIT is a common license for an open source repo.
Line 8–10: State your dependencies.
Line 12–14: Use to move the file into the formula’s directory () and make it executable ().

If you have directories, you can use to install directories:

def install    
bin.install "gitstart"
bin.install Dir["./lib"]
bin.install Dir["./files"]
end

Step 5. Add, Commit, and Push

Once it is ready, add the file, commit, and push.

$ git add .
$ git commit -m "Version 0.2.0"
$ git push

Step 6. Remove gitstart.rb From the Homebrew Formula dir

You need to remove the gitstart.rb file from Formula dir.

$ rm  /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/gitstart.rb

Step 7. Tap and Install

Now your tap is ready.

Run using the following command:

$ brew tap shinokada/gitstart
The output from brew tap shinokada/gitstart. Image by Author.

Then run .

The output from brew install gitstart. Image by Author.

Check if it is installed by running . You can uninstall it using .

Checking the installation results. Image by Author.

Update routine

Step 1.

Add and push a new version.

$ git tag -a v0.2.1 -m "version 0.2.1"
$ git push origin v0.2.1

Repeat Step 2 above:

Creating a new release. Image by Author.

When you update your repo, you need to create a new sha256.

$ brew create https://github.com/shinokada/gitstart/archive/refs/tags/v0.2.1tar.gz

Update the URL value and copy and paste the new sha256 value to your homebrew-gitstart, which you created in Step 4.

Step 2. Remove gitstart.rb from the homebrew Formula dir

Same as Step 6 in the previous section. Remove gitstart.rb from the homebrew formula directory. Otherwise, it will conflict with your repo:

$ rm /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/gitstart.rb

Step 3. Run brew upgrade

$ brew upgrade
The output from brew upgrade. Image by Author.

Run :

The output from brew install gitstart. Image by Author.

Check the new version:

$ gitstart -v
0.2.2

Tips

untap

When you update homebrew-your-repo, you may need to uninstall and untap the local file:

$ brew uninstall --force backpack_install
$ brew untap shinokada/gitstart
Untapping shinokada/gitstart...
Untapped 1 formula (13 files, 7.1KB).

uninstalls a package but not the file. By running , it removes the file.

Then you can tap your new repository:

$ brew tap shinokada/gitstart

alias

When you are developing locally you need to link/unlink your local file. I added an alias as follows:

alias addsym='brew uninstall gitstart && ln -sf ~/Bash_Projects/Gitstart/gitstart-repo/gitstart ~/bin/gitstart'
alias rmsym='rm ~/bin/gitstart && brew upgrade && brew install gitstart'

The uninstalls the gitstart formula from Homebrew and adds a symlink to directory. (I exported the path in the file.)

The removes the symlink and runs and .

What’s Next?

Homebrew’s Formula Cookbook has more detailed instructions. Homebrew Ruby API on Class Formula provides all methods and attributes. If you are using a Make file, Learn Makefiles is a great place to start. You can browse Homebrew-core formula to learn how experienced developers make their formula.

Conclusion

There has more information about Hombrew Taps. My repo is a simple bash script, but if your repo is more complex, you may need to check the build system, specifying conflicts with other formulae, add a test to the formula, and more.

I hope this article made it clear how to create your Homebrew formula. Please let me know how it goes and post your questions or comments.

Happy coding.

If you like my article and would like to receive my newsletter, please sign up.

References

Better Programming

Advice for programmers.

Thanks to Cecilie Okada, Emile Okada, 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