Skip to content
Latchkey

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 metadata

Common 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

Run this faster and cheaper on Latchkey managed runners. Start free →