go mod init: Usage & Common CI Errors
Start a new Go module.
go mod init creates a go.mod file declaring the module path - the import prefix for your packages. The path is usually your repository URL, e.g. github.com/owner/repo.
What it does
Writes a minimal go.mod with a module directive and a go version directive. After this, go get / go build populate the require entries as you add dependencies.
Common usage
Terminal
go mod init github.com/owner/repo # explicit module path
go mod init # infer path from VCS metadataCommon CI error: cannot determine module path
go mod init with no argument fails with "go: cannot determine module path for source directory ... (outside GOPATH, module path must be specified)" because there is no VCS remote to infer from. Fix: pass the path explicitly, e.g. go mod init github.com/owner/repo.
Related guides
go mod tidy: Usage, Options & Common CI Errorsgo mod tidy adds missing and removes unused dependencies in go.mod and go.sum. Learn the -go flag and how to…
go build: Usage, Options & Common CI Errorsgo build compiles Go packages and binaries. Learn -o, ./..., cross-compiling with GOOS/GOARCH, and how to fix…
go work: Usage, Options & Common CI Errorsgo work manages multi-module workspaces with a go.work file. Learn go work init, go work use, and whether to…