Go "go install: requires a version" - Fix in CI
Outside a module, go install must be told which version to fetch via an @version suffix. Without it, Go has no module context to resolve the package and refuses to install.
What this error means
A CI step fails with go install: X: requires a version when current directory is not in a module. A tool was installed without an @version suffix.
go
go install: golang.org/x/tools/cmd/stringer: requires a version when current directory is not in a moduleCommon causes
Missing @version suffix
go install was called without @latest or a pinned version while outside a module.
Old go get habit
A pre-1.16 go get command was carried over, which modern Go rejects for installs without a version.
How to fix it
Add an @version suffix
- Append @latest or a pinned version to the install path.
shell
go install golang.org/x/tools/cmd/stringer@latestPin a specific version
- Pin an exact version for reproducible tool installs.
shell
go install golang.org/x/tools/cmd/stringer@v0.21.0How to prevent it
- Always include @version when installing tools in CI.
- Pin exact versions for reproducible builds.
- Prefer a tools.go file to track tool versions.
Related guides
Go "protoc-gen-go: program not found" - Fix in CIFix protoc "protoc-gen-go: program not found or is not executable" in CI - the Go protobuf plugin is not inst…
Go "go generate: no such tool" - Fix in CIFix Go "go generate" failing with "no such tool" in CI - the //go:generate directive named a generator that i…
Go "malformed module path: missing dot" - Fix in CIFix Go "malformed module path: missing dot in first path element" in CI - the module path is not a valid host…