Create a new go.mod for the current project.

Section: Modules Basics

Initialize module

bash
bash
go mod init example.com/myapp
Explanation

Create a new go.mod for the current project. Useful in Go CLI workflows.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Modules Basics
Tidy dependencies
Add missing and remove unused module requirements.
OpenIn sheetbashsame section
Download dependencies
Pre-fetch required modules into the module cache.
OpenIn sheetbashsame section
Print module graph
Show the module dependency graph.
OpenIn sheetbashsame section
Explain dependency
Show why a package or module is needed.
OpenIn sheetbashsame section
Add replace directive
Point a module dependency to a local checkout.
OpenIn sheetbash2 tag match
Add require directive
Add an explicit module requirement.
OpenIn sheetbash2 tag match