Go Binaries is an open-source server which compiles Go binaries on-demand, allowing non-Go users to quickly install tools written in Go, without installing the Go compiler or a package manager — all you need is
curl. Let’s take a look at how to use it, and how it works!
Suppose you want to install the fantastic hey HTTP benchmarking tool, you could install the latest release with the following command. In a few seconds you’ll have the
hey command available on your machine, installed to
/usr/local/bin by default.
$ curl -sf https://gobinaries.com/rakyll/hey | sh ==> Downloading github.com/rakyll/hey@master ==> Resolved version master to v0.1.3 ==> Downloading binary for darwin amd64 ==> Installing hey to /usr/local/bin ==> Installation complete $ hey https://apex.sh Response time histogram: 0.008  |■ 0.018  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.027  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.036  | ...
In scenarios such as continuous integration you may want to lock down a particular version to prevent any surprises using semver. Go Binaries currently supports the following syntax for matching versions:
vis optional, regardless of the Git tag
Here are a few examples:
$ curl -sf https://firstname.lastname@example.org | sh $ curl -sf https://email@example.com | sh $ curl -sf https://firstname.lastname@example.org | sh $ curl -sf https://email@example.com | sh
The path provided to gobinaries.com should be the full path to your
main package, for example, my staticgen project has the main in
cmd/staticgen/main.go, so it is installed as the following:
$ curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | sh
By default, binaries are installed to
/usr/local/bin, however, you can change the target directory using the
PREFIX environment variable.
Here we install to the current working directory, which can be useful for continuous integration such as GitHub Actions:
$ curl -sf https://gobinaries.com/rakyll/hey | PREFIX=. sh $ ./hey https://apex.sh ...
If the directory doesn’t exist it will be created.
The request for a package resolves the requested version to a Git tag, and responds with a shell script which should be piped to
sh. This is necessary because the server needs to determine your operating system and architecture to cross-compile the Go binary appropriately.
$ curl -sf https://gobinaries.com/rakyll/hey | sh
The shell script performs a second request to gobinaries.com to fetch and install the actual binary, with the OS, architecture, and a concrete version number. If the package was not previously built, it will be cross-compiled be stored in Google Cloud Storage for up to 30 days, and cached in a CDN. This secondary request looks like this:
As I mentioned this is a hosted service, however, the source is also available over at tj/gobinaries, so feel free to take a look and contribute if you’d like.