GOBIN not set: cannot run go install

Update 2020: since Go 1.11 and the introduction of Go modules, GOPATH is not needed anymore per project, and defaults to ~/go for global tools/project you would go get.

Go 1.16 (Q1 2020) should default GOBIN to GOPATH[0]/bin.

But for now, for any project using modules, you would not have an error message like "go install: no install location ..." anymore.


Original answer 2014:

Check your GOPATH variable.
Make sure:

  • your sources are under GOPATH/src
  • you have a bin folder within your GOPATH folder.

See GOPATH environment variable (where 'DIR' is a GOPATH folder):

The bin directory holds compiled commands.
Each command is named for its source directory, but only the final element, not the entire path. That is, the command with source in DIR/src/foo/quux is installed into DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped so that you can add DIR/bin to your PATH to get at the installed commands.

If the GOBIN environment variable is set, commands are installed to the directory it names instead of DIR/bin. GOBIN must be an absolute path.


For instance, this thread illustrates what happen in the case where a go build is done outside of GOPATH/src:

Looks like your GOPATH is set to ~/go but you ran the go install command on ~/dev/go

See Go Build

The Go path is a list of directory trees containing Go source code. It is consulted to resolve imports that cannot be found in the standard Go tree.

If you have done go build, you can also try a go install (no custom.go): you want to install the package, not a single file.


I set the GOBIN path and that worked for me

export GOBIN=[WorkspacePath]/bin

Tags:

Go