Skip to content
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: print default GOBIN when running "go env GOBIN" if not set #34522

Closed
leitzler opened this issue Sep 25, 2019 · 5 comments
Closed

cmd/go: print default GOBIN when running "go env GOBIN" if not set #34522

leitzler opened this issue Sep 25, 2019 · 5 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.

Comments

@leitzler
Copy link
Contributor

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.

@leitzler
Copy link
Contributor Author

@gopherbot, please add label GoCommand

@gopherbot gopherbot added the GoCommand cmd/go label Sep 25, 2019
@mvdan
Copy link
Member

mvdan commented 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 to PATH in some environments.

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 25, 2019
@mvdan
Copy link
Member

mvdan commented Sep 25, 2019

Also note that some env vars like go env GOPATH and go 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 like GOBIN; after a quick scan I could only find GOTMPDIR, which might not have a static default value.

@bcmills
Copy link
Contributor

bcmills commented Sep 25, 2019

go env GOBIN does return the value of GOBIN:

~$ GOBIN=/tmp/foo go env GOBIN
/tmp/foo

GOPATH[0]/bin is used very similarly in module mode, but it is not yet the same — especially in GOPATH mode, which despiteallobjections continues to exist.

@bcmills
Copy link
Contributor

bcmills commented Sep 25, 2019

Duplicate of #23439

@bcmills bcmills marked this as a duplicate of #23439 Sep 25, 2019
@bcmills bcmills closed this as completed Sep 25, 2019
@leitzler leitzler changed the title cmd/go: return current GOBIN when running "go env GOBIN" cmd/go: print default GOBIN when running "go env GOBIN" if not set Sep 25, 2019
@golang golang locked and limited conversation to collaborators Sep 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants