How to Use Homebrew to Distribute Go CLI Tools

Cli
Create a custom Homebrew tap with a Ruby formula to build and install your Go CLI tool for distribution.

Homebrew does not natively support distributing Go CLI tools; you must create a custom tap with a formula that specifies the Go build command and installation path. Create a formula file in your tap's Formula directory that uses url to point to your Go binary or go to build from source, then use brew install to add it to your system.

class MyCli < Formula
  desc "My Go CLI Tool"
  homepage "https://example.com/mycli"
  url "https://example.com/mycli-1.0.0.tar.gz"
  sha256 "<insert-sha256>"

  def install
    bin.install "mycli"
  end

  test do
    system "#{bin}/mycli", "--version"
  end
end

Run brew tap youruser/yourrepo followed by brew install yourrepo/mycli to distribute and install the tool.