Skip to main content

How to manage dependencies with go mod

Go modules is the built-in dependency system provided by Go. It supersedes dep, which we previously used to manage Go dependencies.

It's important to note that go mod uses a different dependency resolution algorithm than many other packaging tools. It will install oldest indirect dependency (called minimal version selection) that will satisfy all direct dependencies, whereas other package managers will tend to install the newest. You can read more about the rationale behind this approach in the original proposal.

For the most part, a developer interacts with go mod using go get. The other go tools are likewise aware of how to work with go modules.

Update all go dependencies

$ go get -u

Update a specific dependency

$ go get -u github.com/pkg/errors

Update a specific dependency to a specific branch

The following updates github.com/pkg/errors to the latest version available on the master branch:

$ go get -u github.com/pkg/errors@master