Go Modules

View saved

Start a module

Inside your project folder, create a go.mod with a module path.

mkdir greeter && cd greeter
go mod init example.com/greeter

Add code and build

With a module initialized, place packages under that folder and build.

go build
go run .

Add a dependency

Import an external package, then download and record it.

go get golang.org/x/example/hello
go mod tidy

Module files

  • go.mod lists the module path and requirements
  • go.sum stores checksums—commit both
  • go mod tidy removes unused requirements
  • Module paths often look like repository URLs

Comments

One comment per signed-in account. Comments are saved with this page’s URL.