Skip to content

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

Closed
@leitzler

Description

@leitzler

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.

Activity

leitzler

leitzler commented on Sep 25, 2019

@leitzler
ContributorAuthor

@gopherbot, please add label GoCommand

mvdan

mvdan commented on Sep 25, 2019

@mvdan
Member

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.

added
NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
on Sep 25, 2019
mvdan

mvdan commented on Sep 25, 2019

@mvdan
Member

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

bcmills commented on Sep 25, 2019

@bcmills
Contributor

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

bcmills commented on Sep 25, 2019

@bcmills
Contributor

Duplicate of #23439

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[/+] on Sep 25, 2019
locked and limited conversation to collaborators on Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeGoCommandcmd/goNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @leitzler@mvdan@bcmills@gopherbot

        Issue actions

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