Safeguard
Developer Tools•

go.mod go line vs toolchain line: what does GOTOOLCHAIN do?

The go line sets a module's minimum Go version. The toolchain line suggests a toolchain, and GOTOOLCHAIN decides whether Go may download one.

Safeguard Security Team
3 min read

In go.mod, the go line is the minimum Go version a module needs. The toolchain line suggests a toolchain to use. The GOTOOLCHAIN setting controls whether the go command may switch to or download a newer toolchain. The default behavior allows switching to one required by go.mod.

Definitions

go line. The minimum Go version needed to use the module. Since Go 1.21 it is mandatory. A toolchain refuses to load a module that requires a newer version, and the line also sets the language version the compiler enforces.

toolchain line. A suggested toolchain. If omitted, it is implicitly the same as the go line.

GOTOOLCHAIN. An environment setting that decides which toolchain the go command runs.

GOTOOLCHAIN values

ValueBehavior
localAlways use the bundled toolchain
autoSame as local+auto, the standard default
pathSame as local+path
go1.21.3Always use that exact toolchain
name+autoStart with the named toolchain, switch if go.mod needs newer
name+pathLike +auto but search PATH only, with no download

Why this is a security matter

Automatic switching is convenient, because a dependency can say it needs a newer Go and your tooling follows. It also means your build can download and run a toolchain you did not install. Go documents the safeguards: toolchains are modules served under golang.org/toolchain, verified through the checksum database, and downloads honor GOPROXY. If GOSUMDB is off, toolchain downloads fail because they cannot be verified.

For locked down build environments, the options are clear:

  • Set GOTOOLCHAIN=local if you want builds to use only what is installed and fail on a mismatch.
  • Use +path if you want to allow switching but only to toolchains you placed on PATH.
  • Pin an exact version such as go1.26.9 when you want reproducible builds.

How a version gets chosen

When a command needs a newer version, Go picks the oldest candidate that satisfies the requirement from the latest release candidate of an unreleased version, the latest patch of the most recent release, or the latest patch of the previous release. It then writes the new go and toolchain lines, so later runs select it without a message.

Handy commands

go env GOTOOLCHAIN
go get go@1.26.9
go get toolchain@none

Practical advice

  1. Set the go line to the lowest version your code truly needs, and keep it on a supported release.
  2. Decide per environment: developers may use auto, release builds may use local.
  3. Log the toolchain version in CI so a silent switch is visible.
  4. Review any pull request that raises the go line, because it changes the build requirement for everyone.

See How long is a Go version supported for the support rule.

Try it yourself

The gate pull request demo shows a check running on a change. A go line bump is a good thing to gate.

Click through it at your own pace, or open it full screen.

Safeguard policies and gates can run checks on pull requests. The free scan is at gold.safeguard.sh/scan.

Quick check

Does Go download toolchains by default?

If a newer toolchain is required by go.mod and the setting allows it, yes. Set GOTOOLCHAIN to local to prevent that.

Is a downloaded toolchain verified?

Per the Go documentation, it is verified through the checksum database.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.