在哪里可以得到安装软件包?

我已经得到了运行 go get <some-remote-git-repo>的指令,它似乎成功了,但是我不清楚软件包安装在哪里,所以我可以从中运行一个可执行文件。

按照 https://golang.org/doc/code.html#remote,它似乎将被安装在 $GOPATH/bin中,但是在我的 shell 中没有定义 $GOPATH(尽管 go get命令似乎工作得很好)。Go 是通过自制软件安装的。

60249 次浏览

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.

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.

go env

you can get the path from GOMODCACHE

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