Go: install: GOPATH/bin not added to PATH on install

Created on 15 Feb 2019  ·  5Comments  ·  Source: golang/go

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

$ go version
go version go1.11.5 darwin/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mmatthias/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mmatthias/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/yp/hpn6fn356nzfqkk0l319033c00kx44/T/go-build874912687=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Download & installed Mac package from https://golang.org/dl/
  2. go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
  3. jb

What did you expect to see?

The help output for the jb command

What did you see instead?

bash: jb: command not found

Solution

I got this to work by adding ~/go/bin to my $PATH.

Either the Mac installer should do this automatically, or there needs to be an update to the documentation https://golang.org/doc/install to note that to be able to install and run third-party go binaries, you'll need to add this directory to your $PATH.

FrozenDueToAge

Most helpful comment

Hi, for what it's worth, I'm brand new to Go and have stumbled into this exact issue (whilst installing govendor) and ended up on this page when searching for a solution.

All 5 comments

I believe that is not a good idea. GOPATH can be set to things other than $HOME/go and installing Go should not be modifying user profile (I personally would not like anything that takes liberty of modifying my profile without asking me first).

Generally it is a trivial thing to do by yourself (by editing $HOME/.bash_profile). Also this is not specific for macOS (OSX is no more, btw). Go installation does not do this on any system (on Linux it depends on package maintainers if install from 3rd party repos).

See https://golang.org/doc/code.html#GOPATH, linked from https://golang.org/doc/install#testing:

Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.

Thanks. As @bcmills noted, this is properly documented, so I’m going to close this issue. If you’re not satisfied with this outcome, feel free to comment.

I don't understand how a comment in the article titled "How to Write Go Code" helps someone downloading and using a Go tool. If a user wants to be able to install packages via go get, then it's required that they're a Go developer and go through that tutorial too?

I think adding a sentence to the Go install documentation to talk about the GOPATH would be very helpful for people installing Go so they can use a Go binary via go get. As it stands, there isn't a clear way for someone to install Go and run go get and then be able to use the downloaded binary.

Edit: I agree with @akamensky that it's trivial to fix this from a user's perspective and it's probably not the best thing to automatically do during install, but this should be called out to the user via documentation or command output.

The thing I'm trying to call out here is how you do you address this flow for new Go people:

  1. Install Go
  2. go get <pkg>
  3. try to run pkg

Not saying you should be able to run pkg, just saying it should be clearer in documentation what is needed to be able to run pkg on a fresh install.

Hi, for what it's worth, I'm brand new to Go and have stumbled into this exact issue (whilst installing govendor) and ended up on this page when searching for a solution.

Was this page helpful?
0 / 5 - 0 ratings