New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: GOBIN inconsistently not required for installing package but required for .go file #23439

sslavic opened this Issue Jan 13, 2018 · 5 comments


None yet
7 participants

sslavic commented Jan 13, 2018

What version of Go are you using (go version)?


Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

Linux, amd64

What did you do?

$ docker run -it --rm --name test golang:1 bash
$ go get
$ go install /go/src/

What did you expect to see?

/go/bin/stan-pub binary installed, consistent with the requirements when go install <package> is used, just GOPATH is set and that should be enough, GOBIN should not be required.

What did you see instead?

Error message:
go install: no install location for .go files listed on command line (GOBIN not set)


This comment has been minimized.


cznic commented Jan 13, 2018

Arguments of go install are documented to be packages, not files. Try

$ go get
$ go install


$ go build /go/src/

This comment has been minimized.

sslavic commented Jan 13, 2018

Thanks @cznic for your comment. What I understand from documentation and implementation is that the name of the argument is packages, but .go files being passed is documented as special case (it's not documented that it works only if GOBIN is set, and I would like that to be fixed not to require GOBIN). I.e. see

$ go install --help
usage: install [build flags] [packages]

Install compiles and installs the packages named by the import paths,
along with their dependencies.

For more about the build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.

See also: go build, go get, go clean.

Notice there go help packages reference.

$ go help packages
Many commands apply to a set of packages:

	go action [packages]


As a special case, if the package list is a list of .go files from a
single directory, the command is applied to a single synthesized
package made up of exactly those files, ignoring any build constraints
in those files and ignoring any other files in the directory.


If one go install, it results in unwanted behaviour, just first main/app in directory with 3 apps gets installed to /go/bin, stan-bench, with examples as binary name. Yes, example apps are preferred by convention to be in dedicated packages/dirs, but they aren't - I've logged improvement ticket for that (see nats-io/go-nats-streaming#164). Even without them being in dedicated packages/dirs, by the docs go file name should be enough, it should be used as package name and resulting binary name. Since the special case docs does not mention that it additionally requires GOBIN to be set, implementation should be fixed not to require it, or docs could be updated to mention GOBIN is required in this case - I prefer former.

Second suggestion, to go build /go/src/ builds stan-pub binary into current working directory, which makes it a partial workaround to go install inconsistency issue, but that does not fix the inconsistency.

This ticket is intended to fix the inconsistency in go install, inconsistency affecting many e.g. see

@titanous titanous added the NeedsFix label Jan 16, 2018

@titanous titanous added this to the Go1.11 milestone Jan 16, 2018

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jul 2, 2018

@gopherbot gopherbot removed the NeedsFix label Oct 2, 2018


This comment has been minimized.


rsc commented Oct 24, 2018

The use of GOPATH/bin only applies to packages stored in GOPATH.
In general GOPATH is a list of tree roots, and a package in one root gets installed to the corresponding bin directory.

go install /other/file.go is not considered to be in any GOPATH, so it can only use GOBIN.

In the long term, with modules, we expect that people will stop setting GOPATH and then GOBIN may be more important (or maybe it will increase pressure to default to GOPATH[0]/bin).


This comment has been minimized.


rsc commented Oct 24, 2018

FWIW I would put the examples in subdirectories and then you can go install blah/blah/examples/...


This comment has been minimized.


rsc commented Oct 25, 2018

Note that if we do make GOBIN effectively default to GOPATH[0]/bin, then we could make 'go env GOBIN' show that default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment