go get adds or changes a dependency in your module, and go mod tidy cleans go.mod and go.sum so they match the imports your code actually uses. A normal workflow is to write the import, run go mod tidy to fetch it, and use go get package@version when you need a specific version or an upgrade.
Both commands edit the same files but with different jobs. This guide shows what each one does, how version queries work and when to run which.
Since Go 1.17, go get is used only to manage dependencies in go.mod. It no longer builds or installs programs; use go install for that.
@v1.6.0 pins an exact version.@latest asks for the newest tagged release explicitly.@none removes the requirement.The command downloads the module into the module cache, then updates the require line in go.mod and the hashes in go.sum.
The identifier changes on every run. If you write the import first and the module is missing from go.mod, the build says no required module provides package, and go get or go mod tidy fixes it.
go mod tidy scans every package in your module, including test files, and compares the imports to go.mod.
require entries for modules your code imports.// indirect.go.sum and drops stale ones.Run it after adding or deleting imports, before committing, and in CI with a check that the files did not change. Running go mod tidy -diff prints what would change without writing anything and exits non-zero if the files need an update.
| Goal | Command |
|---|---|
| Show available updates | go list -m -u all |
| Upgrade one module to the latest release | go get example.com/lib@latest |
| Upgrade patch versions only | go get -u=patch example.com/lib |
| Upgrade a module and its dependencies | go get -u example.com/lib |
| Upgrade everything your build uses | go get -u ./... |
| Downgrade to a known good version | go get example.com/[email protected] |
After any upgrade, run go mod tidy and your tests. Go uses Minimal Version Selection, so adding a dependency never bumps unrelated modules unless you ask with -u.
Version queries are not limited to tags: @main or @branchname follow a branch, and @abc1234 picks a commit. Go records these as pseudo-versions like v0.0.0-20260115103000-abc123456789. Prefer tagged releases for anything you ship.
go mod tidy (or go get for that module).go get module@version, then go mod tidy.go mod tidy drops it.go.mod: run go mod download if you want everything fetched up front, or just build.Start with a new module and one import, then watch the files change.
Create main.go with the uuid program above. Running go build now fails because go.mod has no requirement for the package. Fix it with one command.
go.mod now has a require line and go.sum has two hashes for that version. If you delete the import and run go mod tidy again, both entries disappear. This round trip is the safest way to learn what the command does: change the code, run it, and read the diff of the two files.
no required module provides package: the import is not in go.mod; run go mod tidy or go get.missing go.sum entry: the hash is absent; go mod tidy adds it.unknown revision: the version, tag or branch in your query does not exist or the repository is private. Set GOPRIVATE for private hosts.module declares its path as X but was required as Y: the import path does not match the module line of the dependency.go get changes the requirements of your module. go install package@version builds a command and places the binary in GOBIN, without touching your go.mod.
No. It only adds missing requirements, using the version already selected or the latest if none exists, and removes unused ones.
A dependency may require a newer Go version. The go line cannot be lower than what dependencies need, so the tool raises it.
Rarely. Builds fetch what they need. It is useful in Docker builds to cache dependencies in a separate layer.
Use go get to choose a dependency version and go mod tidy to make go.mod and go.sum match your real imports. Run tidy before every commit, pin or upgrade with @version queries, and test after changes.