go list installed packages: list Go packages, modules, and install paths

go list command for std, ./..., and all; go list -m all for modules; where Go stores packages (GOMODCACHE, GOROOT, GOPATH/bin); list go packages and binaries from go install without mistaking modules for a global package registry.

Published

Updated

Read time 4 min read

Reviewed byDeepak Prasad

go list installed packages: list Go packages, modules, and install paths

People searching for go list installed packages, golang list installed packages, go list installed, go list global packages, go list packages, list go packages, or go packages list usually want one of three things: import paths for the standard library, packages (or modules) tied to a project on disk, or the location of code and binaries the toolchain downloaded or built. The go list command is the supported way to answer the first two; paths come from go env. For how GOPATH and GOROOT differ, see GOPATH vs GOROOT and Go environment variables.

Tested with Go 1.24 on Linux.


go list command: packages and modules

go list prints one line per package (or per module when you pass -m) for the patterns you name. Official reference: List packages or modules.

Standard library: go list std

To list standard-library import paths:

bash
go list std
text
archive/tar
archive/zip
bufio
bytes
cmp
compress/bzip2
compress/flate
compress/gzip
compress/lzw
compress/zlib

Packages in the current module: go list ./... and go list all

From the root of a module (where go.mod lives), go list ./... lists every package under that tree. go list all lists every package in the transitive closure for the main module (standard library plus dependencies), which is a long list—filter with tools like grep when you only need a prefix.

bash
cd /path/to/your/module
go list ./...
go list all | head

Modules (dependency graph): go list -m all

go list -m switches listing to modules instead of packages. go list -m all prints the module versions your main module can build against (your module plus required modules). Run it from inside your project with a go.mod; it is not a “global installed packages” query for the whole machine.

bash
cd /path/to/your/module
go list -m all

Example output shape:

text
example.com/demo
github.com/google/uuid v1.6.0

JSON for modules (trimmed):

bash
go list -m -json all
text
{
	"Path": "example.com/demo",
	"Main": true,
	"Dir": "/path/to/your/module",
	"GoMod": "/path/to/your/module/go.mod",
	"GoVersion": "1.22"
}
{
	"Path": "github.com/google/uuid",
	"Version": "v1.6.0",
	"Time": "2024-01-23T18:54:04Z",
	"Dir": "/home/you/go/pkg/mod/github.com/google/uuid@v1.6.0",
	"GoMod": "/home/you/go/pkg/mod/cache/download/github.com/google/uuid/@v/v1.6.0.mod",
	"Sum": "h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=",
	"GoModSum": "h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo="
}

Custom columns: -f

-f uses Go’s text/template syntax on the package or module struct. For a single package, show where sources live:

bash
go list -f '{{.ImportPath}} -> {{.Dir}}' encoding/json
text
encoding/json -> /usr/local/go/src/encoding/json

Inside a module, the same template on a dependency shows the module cache directory:

bash
go list -f '{{.ImportPath}} -> {{.Dir}}' github.com/google/uuid
text
github.com/google/uuid -> /home/you/go/pkg/mod/github.com/google/uuid@v1.6.0

The -e flag relaxes errors for missing or invalid packages so listing can continue; it does not mean “exportable only.” Use it when you intentionally want partial results from a messy pattern set.


Where go packages and binaries live

Run:

bash
go env GOROOT GOMODCACHE GOPATH

Typical roles:

  • GOROOT — Go toolchain and standard library sources (go list std paths resolve under here).
  • GOMODCACHE — Downloaded module contents (versioned directories under …/pkg/mod/... by layout convention).
  • GOPATH — Still defines default locations: GOPATH/bin for installed commands when GOBIN is empty, and often hosts pkg/mod under the same tree unless GOMODCACHE overrides it.

There is no single global “registry” directory that enumerates every package ever used on the machine; the module cache grows as you build different projects.


Commands installed with go install

go install builds a command and places the binary in GOBIN if that variable is non-empty, otherwise in $(go env GOPATH)/bin. To see what you have on PATH, list that directory (for example ls "$(go env GOPATH)/bin").

To see build metadata embedded in any Go-built executable:

bash
go version -m "$(command -v gofmt)"
text
/usr/local/go/bin/gofmt: go1.24.4
	path	cmd/gofmt
	build	-buildmode=exe
	build	-compiler=gc

The first line is the go version that built the binary; path names the command module. Binaries you built with go install from the module proxy often add mod and dep lines as well—run the same command on a file under $(go env GOPATH)/bin.


Summary

The go list command answers “which import paths or modules exist for this pattern,” not “everything ever installed system-wide.” Use go list std for the standard library, go list ./... and go list all for packages in a module context, and go list -m all for module versions in the current main module. On disk, standard library code sits under GOROOT, cached modules under GOMODCACHE, and go install binaries under GOBIN or GOPATH/bin. Pair go list -f or -json when you need directories and versions in scripts.


References


Frequently Asked Questions

1. Is there a single go list installed or go list global packages subcommand?

No. go list always works from patterns (like std, ./..., or an import path). Installed commands from go install live as files under GOBIN or GOPATH/bin; dependency code is cached under GOMODCACHE. Use go list -m all inside a module for its module graph, not as a global catalog of every tool on the machine.

2. Where are go packages installed on disk?

Standard library source is under GOROOT (see go env GOROOT). Downloaded modules are under GOMODCACHE (often GOPATH/pkg/mod). Binaries from go install go to GOBIN if set, otherwise GOPATH/bin.

3. What is the difference between go list all and go list -m all?

go list all prints package import paths reachable from the current main module (a large set including dependencies). go list -m all prints module paths and versions in the module graph; it only applies when you are inside a module directory.

4. Does go list std list installed third-party packages?

No. std is only the Go standard library import paths. Third-party code appears when you list patterns like ./..., all, or a concrete module path such as github.com/org/repo/... from inside a module.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …