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 getonly changes dependency requirements in the current module's go.mod and go.sum. It no longer builds or installs binaries.go install pkg@versionbuilds 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
- Q420What does this print? (Hint: consider the go line in go.mod.)
- Q421What does the Go 1.24 tool directive replace, and how do you use it?
- Q423Explain build constraints: the //go:build syntax, filename rules, and common gotchas.
- Q424How would you separate integration tests from unit tests using build tags? What alternatives exist?
- Q425How does go generate work, and what are best practices around it?
- Q426What are the tradeoffs of using cgo? When would you avoid it?