If I understand correctly, go install
puts binaries in $GOBIN
directory.
I tend to forget which packages provide which binaries in $GOBIN
and which packages I go install
-ed.
Is there a way to list packages that are currently go install
-ed?
I could, obviously, do ls $GOBIN
and that'll give me names of binaries. However, I'm looking for a way to get a list of packages with their long names, e.g. github.com/operator-framework/operator-sdk
.
Update: go list ...
(suggested here) does not seem to apply to my case because this command expects me to be in a directory containing go.mod
file. I understand that go list
is designated for listing packages of a project. In my case, I need to find out all packages that are installed into $GOBIN
of my system/user.
For each binary in $GOBIN
, you can use go version -m
to show information about the version of Go and the module versions that were used to build that binary. For example, here's go version -m ~/go/bin/goimports
for me.
$ go version -m ~/go/bin/goimports
/Users/jayconrod/go/bin/goimports: go1.15.2
path golang.org/x/tools/cmd/goimports
mod golang.org/x/tools v0.0.0-20200910165216-53e29e9d1252 h1:qn28WK3EvdJOSlyZFNeWnaEX8X5GiQv+8mrw9mYrXko=
dep golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
dep golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
The path
line shows the name of the main
package that was installed. Looks like I need to update it.
$ go install golang.org/x/tools/cmd/goimports@latest
$ go version -m ~/go/bin/goimports
/Users/jayconrod/go/bin/goimports: go1.17rc1
path golang.org/x/tools/cmd/goimports
mod golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
dep golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
dep golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
dep golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=