GOBIN not set: cannot run go install
I set the GOBIN path and that worked for me
export GOBIN=[WorkspacePath]/bin
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 inDIR/src/foo/quux
is installed intoDIR/bin/quux
, notDIR/bin/foo/quux
. The "foo/
" prefix is stripped so that you can addDIR/bin
to yourPATH
to get at the installed commands.
If the
GOBIN
environment variable is set, commands are installed to the directory it names instead ofDIR/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 thego 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.
As a beginner, I ran across this error when I was trying out various go commands (build, run, and install). In short, you cannot go install a filename.go. You can only install a package.
This was confusing, because I had learned that:
nate:~/work/src/dir $ go run hello/hello.go
hello, world.
works great. But I couldn't figure out why install wouldn't work:
nate:~/work/src/dir $ go install hello/hello.go
go install: no install location for .go files listed on command line (GOBIN not set)
nate:~/work/src/dir $ go install hello
can't load package: package hello: cannot find package "hello" in any of:
/opt/go/src/hello (from $GOROOT)
/home/ubuntu/work/src/hello (from $GOPATH)
No matter what directory I was in:
nate:~/work/src/dir $ cd hello
nate:~/work/src/dir/hello $ go install hello.go
go install: no install location for .go files listed on command line (GOBIN not set)
nate:~/work/src/dir/hello $ go install hello
can't load package: package hello: cannot find package "hello" in any of:
/opt/go/src/hello (from $GOROOT)
/home/ubuntu/work/src/hello (from $GOPATH)
This confusion is because go run only works with Go source files (filenames that end in .go) and go install only accepts packages. Packages are named by their import paths or file system path. Thus:
nate:~/work/src/dir $ go install dir/hello
nate:~/work/src/dir $ go install ./hello/
nate:~/work/src/dir/hello $ go install .
all work great. The first refers to the package by import path, (given that $GOPATH="/home/nate/work", the go tools look for source code in /home/nate/work/src), the others are interpreted as file system paths because of the leading periods.
See also the GOPATH docs.