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: command to print out the directory Go will install binaries into #45546

Open
kevinburkemeter opened this issue Apr 13, 2021 · 7 comments
Open

Comments

@kevinburkemeter
Copy link

@kevinburkemeter kevinburkemeter commented Apr 13, 2021

Go can install binaries into one of several locations, I think:

  • if GOBIN is set, go will install to that directory
  • if GOPATH is set, go will install to GOPATH[0]/bin
  • otherwise (usually), $HOME/go/bin

I'm working with several people who are not really Go programmers, but need to install Go services in order to do their jobs (frontend programming, design, etc). It's a frequent pattern to have instructions that say like "run go install ./... and then start the server" and then they get "meter-server: command not found" because they haven't added whatever directory to their $PATH. So then I need to figure out where Go is actually installing binaries to and then walk them through that process. This is more difficult now when I can't sit right next to them and walk through the commands.

Having a way to easily see which directory Go is installing, or going to, install packages would be very helpful.

Going beyond that, a tool in the x/tools that can append that directory to your $PATH, based on your shell, would be extremely helpful.

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Apr 13, 2021

maybe we can make GOBIN point to the chosen directory if otherwise unset? Then the command would be go env GOBIN

cc @bcmills @jayconrod @matloob

@kevinburkemeter
Copy link
Author

@kevinburkemeter kevinburkemeter commented Apr 13, 2021

"go help environment" reports:

Additional information available from 'go env' but not read from the environment:

    GOEXE
	    The executable file name suffix (".exe" on Windows, "" on other systems).
    GOGCCFLAGS
	    A space-separated list of arguments supplied to the CC command.
    GOHOSTARCH
	    The architecture (GOARCH) of the Go toolchain binaries.
    GOHOSTOS
	    The operating system (GOOS) of the Go toolchain binaries.
    GOMOD
	    The absolute path to the go.mod of the main module.
	    If module-aware mode is enabled, but there is no go.mod, GOMOD will be
	    os.DevNull ("/dev/null" on Unix-like systems, "NUL" on Windows).
	    If module-aware mode is disabled, GOMOD will be the empty string.
    GOTOOLDIR
	    The directory where the go tools (compile, cover, doc, etc...) are installed.
    GOVERSION
	    The version of the installed Go tree, as reported by runtime.Version.

Perhaps we could add another value? GOINSTALLDIR or similar. One issue is GOINSTALLDIR would be less permanent than the values listed above.

@kevinburkemeter
Copy link
Author

@kevinburkemeter kevinburkemeter commented Apr 13, 2021

or "go tool installdir"

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 13, 2021

Duplicate of #23439?

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 13, 2021

Also note that you can use go list -f {{.Target}} $IMPORTPATH to obtain this information for a given package main.

@kevinburkemeter
Copy link
Author

@kevinburkemeter kevinburkemeter commented Apr 13, 2021

If you want "go env GOBIN" to always print the answer to this question instead of being empty if $GOBIN is empty, then yes it's a duplicate, however there are a few different ways to potentially solve this problem.

@kevinburkemeter
Copy link
Author

@kevinburkemeter kevinburkemeter commented Apr 13, 2021

Also note that you can use go list -f {{.Target}} $IMPORTPATH to obtain this information for a given package main.

This is really helpful and does basically what I want, thanks, though I guess the interface could be more intuitive. In the #general channel of the Gophers slack no one has suggested this so far in about 30 minutes, which suggests awareness of this solution is not widespread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants