LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

go-mod

Go module dependency management

TLDR

Initialize new module
$ go mod init [module-name]
copy
Download dependencies
$ go mod download
copy
Tidy dependencies
$ go mod tidy
copy
Vendor dependencies
$ go mod vendor
copy
Verify checksums
$ go mod verify
copy

SYNOPSIS

go mod command [arguments]

DESCRIPTION

go mod manages Go modules, the official dependency management system for Go. Modules are collections of packages with versioned dependencies defined in go.mod files.The command initializes modules, manages dependencies, and maintains reproducible builds. It integrates with module proxies and checksum databases to ensure package integrity and availability.

PARAMETERS

init NAME

Initialize new module.
download
Download modules to cache.
tidy
Add missing, remove unused.
vendor
Create vendor directory.
verify
Verify dependencies.
graph
Print dependency graph.
why PACKAGE
Explain why needed.
--help
Display help information.

CONFIGURATION

go.mod

Module definition file containing module path, Go version, and dependency requirements.
go.sum
Checksums of module dependencies for verification.
GOSUMDB
Name of the checksum database used to verify downloaded modules; set to off to disable verification.
GONOSUMDB
Glob patterns of module paths to exclude from checksum-database verification (defaults from GOPRIVATE if unset).
GOFLAGS
Default flags applied to go commands, including go mod subcommands.

INSTALL

sudo apt install gccgo-go
copy
sudo dnf install gcc-go
copy
sudo pacman -S gcc-go
copy
sudo apk add gcc-go
copy
sudo zypper install gcc-go
copy
brew install go
copy
nix profile install nixpkgs#go
copy

CAVEATS

Requires Go 1.11+. go.sum should be committed. Vendor mode for offline builds.

HISTORY

Go modules were introduced in Go 1.11 as the official dependency management solution, replacing GOPATH-based workflows.

SEE ALSO

go(1), go-get(1)

RESOURCES

Copied to clipboard
Kai