Skip to content

Go modules

A Go module is a collection of related Go packages versioned together as a single unit. Modules replace the old GOPATH‑based workflow and provide:

  • Versioning – Semantic versions (v1.2.3) are enforced.
  • Dependency managementgo.mod lists required modules and versions.
  • Reproducible buildsgo.sum ensures integrity.

The module system was introduced in Go 1.11 and became the default in Go 1.16.

  • go.mod – Defines the module path (e.g., github.com/user/project) and its dependencies.
  • go.sum – Contains checksums of dependencies to verify integrity.
CommandPurpose
go mod init <module>Create a new module in the current directory.
go get <module>Add a dependency (or update it).
go mod tidyRemove unused dependencies and add missing ones.
go mod vendorCopy dependencies to a vendor/ folder (optional).

Create a new module named “hello”.

Terminal window
mkdir myproject
cd myproject
go mod init hello
go: creating new go.mod: module hello

Now go.mod contains:

module hello
go 1.24
Terminal window
go get rsc.io/quote

This updates go.mod and downloads the module.