Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.13 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build575410569=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Run go env GOBIN
What did you expect to see?
The current evaluated path to GOBIN.
It has bitten me a few times where I install tools with go install
and then want to run them, without relying on having GOBIN in my path. I can't really see any reason why go env GOBIN
shouldn't return the current one.
Also see @rsc comment in #23439 (comment)
What did you see instead?
An empty line.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
leitzler commentedon Sep 25, 2019
@gopherbot, please add label GoCommand
mvdan commentedon Sep 25, 2019
There's also
go list -f {{.Target}} path/to/main
, but that requires knowing the full package path (and resolving it!), and doesn't return the directory. The directory can be useful for many things, such as adding it toPATH
in some environments.mvdan commentedon Sep 25, 2019
Also note that some env vars like
go env GOPATH
andgo env GOCACHE
correctly return the default values when the user hasn't set one up. I'm not sure if there are any other flags that are inconsistent likeGOBIN
; after a quick scan I could only findGOTMPDIR
, which might not have a static default value.bcmills commentedon Sep 25, 2019
go env GOBIN
does return the value ofGOBIN
:GOPATH[0]/bin
is used very similarly in module mode, but it is not yet the same — especially inGOPATH
mode, whichdespiteallobjections
continues to exist.bcmills commentedon Sep 25, 2019
Duplicate of #23439
[-]cmd/go: return current GOBIN when running "go env GOBIN"[/-][+]cmd/go: print default GOBIN when running "go env GOBIN" if not set[/+]