88

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.

Liron Yahdav
  • 10,152
  • 8
  • 68
  • 104
  • 1
    For those who find this question: note that installing with go get is deprecated. See my answer [here](https://stackoverflow.com/a/68809471/4108803) for further info – blackgreen Aug 17 '21 at 06:13

5 Answers5

97

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.

Liron Yahdav
  • 10,152
  • 8
  • 68
  • 104
  • 16
    Just to add to this, this is not particular to homebrew but GO in general. You can also do `go env GOPATH` to check where your GOPATH is pointed to as mentioned in [this doc](https://golang.org/doc/gopath_code#GOPATH) – shriek Jul 22 '21 at 13:05
17
go env

you can get the path from GOMODCACHE

Daisy
  • 171
  • 1
  • 4
6

Even if you don't have a $GOPATH variable you can see what it uses by doing go env GOPATH.

Try this to see what your path is:

echo `go env GOPATH`/bin
mvndaai
  • 3,453
  • 3
  • 30
  • 34
5

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.

Andrew W. Phillips
  • 3,254
  • 1
  • 21
  • 24
-3

Using go build

Try this with main.go. In your greeter directory, run the following command:

go build

In this case, you built your greeter application into an executable file that was added to your current directory. Check this by running the ls command:

ls
./greeter
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Netwons
  • 1,170
  • 11
  • 14