Go

What is the difference between go get and go install pkg@version in module mode?

Question 422MediumGo 1.22 to 1.25

Since Go 1.17/1.18 the jobs are separate:

  • go get only changes dependency requirements in the current module's go.mod and go.sum. It no longer builds or installs binaries.
  • go install pkg@version builds and installs a binary ignoring the current module. It runs in "module-aware, outside any module" mode, using the target module's go.mod as the main module.
go get github.com/rs/zerolog@v1.33.0     # add/upgrade a dependency
go get github.com/rs/zerolog@none        # remove it
go get -u ./...                          # upgrade direct+indirect deps (minor/patch)
go get -u=patch ./...                    # patch-level only

go install golang.org/x/tools/gopls@latest   # install a tool globally
go install ./cmd/server                      # install from current module (no @)

Gotchas: go install mod@version fails if the target's go.mod has replace or exclude directives, because the build must mean the same thing everywhere. The binary goes to $GOBIN (default $GOPATH/bin). For project-pinned tools, prefer the 1.24 tool directive over global installs.

More on Modules, Packages & Tooling

All 36 Modules, Packages & Tooling questions