Where does go get install packages?

GoHomebrew

Go Problem Overview


I've been given instructions to run go get <some-remote-git-repo> which seems to succeed, but it's not clear to me where the package was installed to so I can run an executable from it.

Per https://golang.org/doc/code.html#remote it seems it will be installed in $GOPATH/bin but $GOPATH isn't defined in my shell (though the go get command seems to work fine). Go is installed via Homebrew.

Go Solutions


Solution 1 - Go

I found the missing clue by running brew info go, which says:

==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
  https://golang.org/doc/code.html#GOPATH

From that I found the executable in question at $HOME/go/bin.

Solution 2 - Go

I had a similar problem which is why I found your question. However, in my case I did not have an empty GOPATH but one with multiple directories. I worked out the issue and describe it here...

If you run go get and you already have the package it says nothing (even with the -v option). This is confusing if it's not in the first directory of your GOPATH. Ie you run go get , there is no error or any message but when you check the first directory of the GOPATH (which is where the doc says it should be) you can't find it.

I eventually found it, but since I have a large GOPATH this was rather tedious.

Solution 3 - Go

go env

you can get the path from GOMODCACHE

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLiron YahdavView Question on Stackoverflow
Solution 1 - GoLiron YahdavView Answer on Stackoverflow
Solution 2 - GoAndrew W. PhillipsView Answer on Stackoverflow
Solution 3 - GoDaisyView Answer on Stackoverflow