go get adds or retrieves external package dependencies for a Go project. It accepts an individual package path or ./..., which scans the codebase for referenced external packages. section 1.2.4
Use go get for common dependency-management tasks:
- Run go get PACKAGE_PATH to retrieve one package, such as golang.org/x/net/html. section 1.2.4
- Run go get ./... to walk the codebase and retrieve referenced external packages. section 1.2.4
- Run go get PACKAGE_PATH@VERSION to select a semantic-version tag rather than the latest version. section 6.1.3
- Run go get -u to update all dependencies, or go get -u PACKAGE_PATH to update one; use go mod tidy afterward. section 6.1.3
- Use go mod graph to inspect updated versions and transitive dependencies, and add -t when test packages matter. section 6.1.3
Adding an external package
Initialize the project with go mod init, import an external package such as golang.org/x/net/html, then run go get ./.... Go retrieves the package through its version-control system and makes it available to the workspace; the dependency is recorded in go.mod. section 1.2.4
$ go get ./...
Inspect the command form used to retrieve every external package referenced throughout a codebase. section 1.2.4
