Go mod Command

Create mod file

At the root directory of the project, create go.mod file using this command:

$ go mod init

Update the mod files

This command will install everything needed by the module and update the go.mod file and create a new file named go.sum, which is the checksum file of the dependencies.

$ go get ./...

tidy the mod file

After we changed some of the required packages, we need to update the go.mod file in order to make it tidy and clean.

For example, after we chage the verson of logrus from v1.4.2 to v1.3.2

github.com/sirupsen/logrus v1.4.2


github.com/sirupsen/logrus v1.3.2

we need to run go mod tidy to update the mod file.

Why we are using this module?

$ go mod why -m  github.com/stretchr/testify
# github.com/stretchr/testify

Create vendor director

Saving all dependences in to vendor directory.

$ go mod vendor


  • justforfunc #42: Intro to Go Modules and SemVer