Go "go.mod requires go >= 1.xx" - Fix in CI
The go directive in go.mod sets a minimum toolchain version. If CI runs an older Go, the build refuses rather than risk using unsupported features.
What this error means
A build fails with go.mod requires go >= 1.22 (running go 1.21; GOTOOLCHAIN=local). It means setup-go pinned an older version than the module declares, or GOTOOLCHAIN=local blocked an auto-upgrade.
go
go: go.mod requires go >= 1.22.0 (running go 1.21.6; GOTOOLCHAIN=local)Common causes
CI Go version below the directive
setup-go installed an older Go than the module go directive requires.
GOTOOLCHAIN=local blocks the upgrade
With GOTOOLCHAIN=local Go will not download a newer toolchain, so an older binary cannot satisfy the directive.
How to fix it
Install a matching Go version
- Set setup-go to the version the module requires (or newer).
.github/workflows/ci.yml
- uses: actions/setup-go@v5
with:
go-version: '1.22'Allow the toolchain auto-download
- Leave GOTOOLCHAIN at auto so Go can fetch the required toolchain when the local one is too old.
.github/workflows/ci.yml
export GOTOOLCHAIN=auto
go build ./...How to prevent it
- Pin the CI Go version to match the go.mod directive.
- Bump setup-go when you raise the go directive.
- Leave GOTOOLCHAIN=auto unless you deliberately pin a toolchain.
Related guides
Go "go.mod file not found in current directory" - Fix in CIFix Go "go.mod file not found in current directory or any parent directory" in CI - the job ran outside the m…
Go "updates to go.mod needed" under readonly - Fix in CIFix Go "updates to go.mod needed; disabled by -mod=readonly" in CI - a readonly build found a required change…
Go cgo "C compiler not found" in CI - Fix the buildFix Go cgo "exec: gcc: executable file not found" in CI - a cgo package needs a C compiler the runner lacks.…