Skip to content
gobin is an experimental, module-aware command to install/run main packages.
Branch: master
Clone or download
myitcv main: fix precedence logic between GOFLAGS and -tags (#76)
Thanks to Roger Peppe for picking this up in the last review.
Latest commit 082f55c May 13, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdata main: fix precedence logic between GOFLAGS and -tags (#76) May 13, 2019
vendor deps: temporarily remove requirement on (#58) Jan 25, 2019
.gitignore main: correctly determine binary name in case path ends with major ve… Mar 21, 2019 ci: add OSes to CI (#49) Dec 3, 2018
.travis.yml ci: use new module proxy (#75) May 10, 2019
LICENSE Initial commit Oct 16, 2018 main: support -tags and GOFLAGS with -tags (#74) May 13, 2019
exitcode_plan9.go main: do not print *exec.ExitError for -run (#61) Feb 16, 2019
exitcode_posix.go main: do not print *exec.ExitError for -run (#61) Feb 16, 2019
go.mod deps: temporarily remove requirement on (#58) Jan 25, 2019
help.go main: support -tags and GOFLAGS with -tags (#74) May 13, 2019
main.go main: fix precedence logic between GOFLAGS and -tags (#76) May 13, 2019
os.go ci: add OSes to CI (#49) Dec 3, 2018
script_test.go main: do not print *exec.ExitError for -run (#61) Feb 16, 2019
tools.go deps: temporarily remove requirement on (#58) Jan 25, 2019


The gobin command installs/runs main packages.

See the FAQ for more details.


$ GO111MODULE=off go get -u

or download a binary from the latest release.

Update your PATH and verify we can find gobin in our new PATH:

$ export PATH=$(go env GOPATH)/bin:$PATH
$ which gobin


Install gohack:

$ gobin
Installed to /home/gopher/gopath/bin/gohack

Install a specific version of gohack:

$ gobin
Installed to /home/gopher/gopath/bin/gohack

Print the gobin cache location of a specific gohack version:

$ gobin -p

Run a specific gohack version:

$ gobin -run -help
The gohack command checks out Go module dependencies
into a directory where they can be edited, and adjusts
the go.mod file appropriately.

Examples: using -m

Define a module:

$ cat go.mod

Add a tool dependency:

$ cat tools.go
// +build tools

package tools

import (
	_ ""

Review the version of stringer being used:

$ gobin -m -p

Check the help for stringer:

$ gobin -m -run -help
Usage of stringer:
	stringer [flags] -type T [directory]
	stringer [flags] -type T files... # Must be a single package
For more information, see:

Use stringer via a go:generate directive:

$ cat main.go
package main

import "fmt"

//go:generate gobin -m -run -type=Pill

type Pill int

const (
	Placebo Pill = iota
	Acetaminophen = Paracetamol

func main() {
	fmt.Printf("For headaches, take %v\n", Ibuprofen)

Generate and run as a "test":

$ go generate
$ go run .
For headaches, take Ibuprofen


The gobin command installs/runs main packages.

	gobin [-m] [-run|-p|-v|-d] [-u|-nonet] [-tags 'tag list'] packages [run arguments...]

The gobin command builds, installs, and possibly runs an executable binary for
each of the named main packages.

The packages argument to gobin is similar to that of the go get command (in
module aware mode) with the additional constraint that the list of packages
must be main packages. Each argument takes the form $main_pkg[@$version].

By default, gobin will use the main package's module to resolve its
dependencies, unless the -m flag is specified, in which case dependencies will
be resolved using the main module (as given by go env GOMOD).

The -mod flag provides additional control over updating and use of go.mod when
using the main module to resolve dependencies. If the -mod flag is provided it
implies -m. With -mod=readonly, gobin is disallowed from any implicit updating
of go.mod. Instead, it fails when any changes to go.mod are needed. With
-mod=vendor, gobin assumes that the vendor directory holds the correct copies
of dependencies and ignores the dependency descriptions in go.mod

This means that gobin $package@v1.2.3 is a repeatable way to install an exact
version of a binary (assuming it has an associated go.mod file).

The version "latest" matches the latest available tagged version for the module
containing the main package. If gobin is able to resolve "latest" within the
module download cache it will use that version. Otherwise, gobin will make a
network request to resolve "latest". The -u flag forces gobin to check the
network for the latest tagged version. If the -nonet flag is provided, gobin
will only check the module download cache. Hence, the -u and -nonet flags are
mutually exclusive.

Versions that take the form of a revision identifier (a branch name, for
example) can only be resolved with a network request and hence are incompatible
with -nonet.

If no version is specified for a main package, gobin behaves differently
depending on whether the -m flag is provided. If the -m flag is not provided,
gobin $module is equivalent to gobin $module@latest. If the -m flag is
provided, gobin attempts to resolve the current version via the main module's
go.mod; if this resolution fails, "latest" is assumed as the version.

By default, gobin installs the main packages to $GOBIN (or $GOPATH/bin if GOBIN
is not set, which defaults to $HOME/go/bin if GOPATH is not set).

The -run flag takes exactly one main package argument and runs that package.
It is similar therefore to go run. Any arguments after the single main package
will be passed to the main package as command line arguments.

The -p flag prints the gobin cache path for each of the packages' executables
once versions have been resolved.

The -v flag prints the module path and version for each of the packages. Each
line in the output has two space-separated fields: a module path and a version.

The -d flag instructs gobin to stop after installing the packages to the gobin
cache; that is, it instructs gobin not to install, run or print the packages.

The -run, -p, -v and -d flags are mutually exclusive.

The -tags flag is identical to the cmd/go build flag (see go help build). It is
a space-separated list of build tags to consider satisfied during the build.
Alternatively, GOFLAGS can be set to include a value for -tags (see go help

It is an error for a non-main package to be provided as a package argument.

Cache directories

gobin maintains a cache of executables, separate from any executables that may
be installed to $GOBIN.

By default, gobin uses the directories gobin/$module@$version/$main_pkg under
your user cache directory. See the documentation for os.UserCacheDir for
OS-specific details on how to configure its location.

When the -m flag is provided, gobin uses the directories
.gobincache/$module@$version/$main_pkg under the directory containing the main
module's go.mod.


You can’t perform that action at this time.