Skip to content
Latchkey

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 module

Common 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

  1. Append @latest or a pinned version to the install path.
shell
go install golang.org/x/tools/cmd/stringer@latest

Pin a specific version

  1. Pin an exact version for reproducible tool installs.
shell
go install golang.org/x/tools/cmd/stringer@v0.21.0

How 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →