golangci/golangci-lint · error

the Go language version (%s) used to build golangci-lint is

Error message

the Go language version (%s) used to build golangci-lint is lower than the targeted Go version (%s)

What it means

CheckGoVersion verifies that the Go language version used to build golangci-lint is not older than the version targeted by the analyzed module's go.mod `go` directive (after TrimGoVersion). This error is returned when runtimeVersion.LessThan(targetedVersion), i.e. the module requires a newer Go than the linter binary supports. go/analysis rejects running analyzers built with an older language version than the target.

Source

Thrown at pkg/goutil/version.go:32

	rv, err := CleanRuntimeVersion()
	if err != nil {
		return fmt.Errorf("clean runtime version: %w", err)
	}

	langVersion := version.Lang(rv)

	runtimeVersion, err := hcversion.NewVersion(strings.TrimPrefix(langVersion, "go"))
	if err != nil {
		return err
	}

	targetedVersion, err := hcversion.NewVersion(TrimGoVersion(goVersion))
	if err != nil {
		return err
	}

	if runtimeVersion.LessThan(targetedVersion) {
		return fmt.Errorf("the Go language version (%s) used to build golangci-lint is lower than the targeted Go version (%s)",
			langVersion, goVersion)
	}

	return nil
}

// TrimGoVersion Trims the Go version to keep only M.m.
// Since Go 1.21 the version inside the go.mod can be a patched version (ex: 1.21.0).
// The version can also include information which we want to remove (ex: 1.21alpha1)
// https://go.dev/doc/toolchain#versions
// This a problem with staticcheck and gocritic.
func TrimGoVersion(v string) string {
	if v == "" {
		return ""
	}

	exp := regexp.MustCompile(`(\d\.\d+)(?:\.\d+|[a-z]+\d)`)

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Upgrade golangci-lint to a version built with a Go toolchain >= the version in your go.mod (`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest`).
  2. Alternatively lower the `go` directive in go.mod if the newer language version is not actually required.
  3. In CI, install the golangci-lint version matching your Go toolchain instead of a pinned stale binary.
  4. Compare the two versions in the message (linter build version vs targeted version) to pick the right upgrade.
  5. Do not bypass the check; mismatched language versions can make analyzers misbehave.

Example fix

// before (go.mod)
go 1.24
// linted with golangci-lint built with Go 1.23 -> fails
// after: upgrade the linter binary
$ go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest  // built with Go 1.24+
Defensive patterns

Strategy: validation

Validate before calling

// Compare your go.mod's go directive with the linter's build Go version first
import hcversion "github.com/hashicorp/go-version"

func checkToolchainCompat(goDirective, linterBuildGoVersion string) error {
	if goDirective == "" {
		return nil
	}
	target, err1 := hcversion.NewVersion(strings.TrimPrefix(goDirective, "go"))
	build, err2 := hcversion.NewVersion(strings.TrimPrefix(linterBuildGoVersion, "go"))
	if err1 == nil && err2 == nil && build.LessThan(target) {
		return fmt.Errorf("upgrade golangci-lint: built with %s, module needs %s", linterBuildGoVersion, goDirective)
	}
	return nil
}

Try / catch

if err := goutil.CheckGoVersion(goVersion); err != nil {
	if strings.Contains(err.Error(), "is lower than the targeted Go version") {
		return fmt.Errorf("upgrade golangci-lint to a build made with Go >= %s: %w", goVersion, err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling CheckGoVersion (via Load) with goVersion from the module's go.mod greater than the linter's build-time Go version — e.g. a module declaring `go 1.24` linted by a golangci-lint binary built with Go 1.23.

Common situations: Bumping the go directive in go.mod after adopting a new language feature without upgrading golangci-lint; CI reusing a cached old golangci-lint binary while the repo moved to a newer Go; distro-packaged golangci-lint built with an older toolchain.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/bfad3da346c3f4e4. Report an issue: GitHub.