# add or update depgo get github.com/path/to/module
# use specific versiongo get github.com/dep/two/v2@v2.1.0
# use specific branchgo get github.com/dep/commit@branch
# upgrade all modules used in subdirsgo get -u ./...
# remove depgo get github.com/dep/legacy@none
# organize and clean up go.mod and go.sumgo mod tidy
# download deps into module cachego mod download
# initialize new modulego mod init github.com/path/to/module
# why is the module a dependency?go mod why -m github.com/path/to/module
# build and install a binarygo install github.com/path/to/bin@latest
To build a program Go needs to know exactly which dependencies you need, and which version to use.
Go uses MVS as a predictable and simple way to decide which version to use.
It works like this:
go.mod
files)go.mod
explicitly specifiedIn this example, the main module depends on A 1.0
and B 2.1
. Since B 2.1
depends on A 1.1
, this is the version of A
that will be used. Since A 1.1
is used, it also pulls in C 1.1
.
The final dependency list is:
A 1.1
B 2.1
C 1.1