debuggoMajor
GOBIN not set: cannot run go install
Viewed 0 times
gobinruninstallsetnotcannot
Problem
I am trying to install my custom package for my main.go file. However, when I ran
I got this error
How do I set GOBIN?
go install custom.goI got this error
go install: no install location for .go files listed on command line (GOBIN not set)How do I set GOBIN?
Solution
Update 2020: since Go 1.11 and the introduction of Go modules,
Go 1.16 (Q1 2020) should default
But for now, for any project using modules, you would not have an error message like "
Original answer 2014:
Check your
Make sure:
See GOPATH environment variable (where 'DIR' is a
The
Each command is named for its source directory, but only the final element, not the entire path. That is, the command with source in
If the
For instance, this thread illustrates what happen in the case where a go build is done outside of
Looks like your
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
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
binfolder 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/goSee 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.Context
Stack Overflow Q#25216765, score: 60
Revisions (0)
No revisions yet.