Skip to content
Tutorials Center
My learning

Topics

Go Reference ยท The go Command and Tools

The go get command

Reference for go get: add or upgrade dependencies, version queries (@latest, @none, @v1.2.3), -u, -t, -tool, downgrades and minimal version selection.

go get changes the dependencies of the module you are working in. It adds a new requirement to go.mod, upgrades or downgrades an existing one, or removes one, and it downloads the code so your next build works. Since Go 1.18 it no longer builds or installs commands: that job belongs to go install.

Each argument has the form module@query. The query says which version you want; without one, go get uses @upgrade, which means the latest release (or keeps what you already have if it is newer).

Terminal
go get github.com/google/uuid          # add, or upgrade to latest
go get github.com/google/uuid@v1.6.0   # exact version
go get golang.org/x/text@none          # remove the requirement
go get -u ./...                        # upgrade dependencies of this module

Try it

Choosing a version is a comparison problem, and Go's rule is simple: among all requirements anywhere in the graph, use the highest minimum. The examples implement the version comparison and that rule with the standard library only.

Go Comparing semantic versions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with bufio.Scanner or fmt.Scan), it gets the next line from this box.

Go Minimal version selection

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with bufio.Scanner or fmt.Scan), it gets the next line from this box.

Syntax

Terminal
go get [-d] [-t] [-u] [-tool] [-x] [build flags] [packages]
Argument or flag Description
module Same as module@upgrade.
module@latest Latest tagged release, or the newest commit if no release exists. Unlike @upgrade, it ignores the version you have now, so it can lower a pre-release to the latest release.
[email protected] Exactly this version. Can be a downgrade.
module@upgrade The latest release unless you already have something newer.
module@patch Latest patch release of the version you currently use.
module@none Remove the requirement. Modules that depended on it may be downgraded too.
module@main, @commit A branch, or a commit hash; recorded as a pseudo-version like v0.0.0-20250102150405-abcdef123456.
module@>=v1.5 A comparison query; the lowest matching version is used.
-u Also update the dependencies of the named packages to their latest minor or patch releases.
-u=patch Update dependencies, but only to patch releases.
-t Also consider modules needed to build the tests of the named packages.
-tool Add a command dependency as a tool directive in go.mod (Go 1.24).
-x Print the commands being run.

Go version bump: if the new dependency needs a newer Go than your go line, go get raises that line, and may require a newer toolchain. Use go get [email protected] to change the language version yourself.

Errors: module ... found, but does not contain package ... means the version has no package at that path (check the major-version suffix: /v2). unknown revision means the query matched no tag or commit.

Usage notes

  • Only changes go.mod and go.sum. No binary is built and nothing is installed. For tools use go install tool@version, or record them with go get -tool and run them with go tool.
  • Upgrade all dependencies: go get -u ./... then go mod tidy. Add -t to include test dependencies. This is a deliberate step; Go never upgrades by itself.
  • Direct versus indirect. Adding a package you import yields a plain require; other modules pulled in appear with // indirect. Run go mod tidy afterwards to settle the marks.
  • Downgrades cascade. Asking for an older version of A may also lower other modules that need A at a higher version, because the build must stay consistent.
  • Major versions are different import paths. github.com/x/y/v2 and github.com/x/y are separate modules. To move from v1 to v2 you change the import path, then go get github.com/x/y/v2.
  • Checksums. New modules are verified against sum.golang.org and recorded in go.sum. Private code should be listed in GOPRIVATE.
  • Outside a module go get does nothing useful; run go mod init first.
  • Obsolete flags. -d (download only) is now the default behavior and is ignored. Old advice that says go get -u tool installs a program is wrong for modern Go.
  • Replace and vendor. With a vendor/ directory, run go mod vendor after changing dependencies so the folder matches.