For years, working on several Go projects meant a version manager: gvm, goenv, asdf, or a hand-rolled set of directories under /usr/local. Go 1.21 changed that. The go command itself can now read the version a module needs, download that toolchain and run it, and the setting lives in go.mod where everyone already looks.

We migrated a monorepo of about forty Go services from gvm to toolchain switching. This guide explains the mechanism, the settings that matter in CI and restricted networks, and the cases where gvm or Go's own wrapper commands are still useful.

Two lines in go.mod

Since Go 1.21, go.mod has two related lines:

module example.com/billing

go 1.23.0

toolchain go1.23.4

Line

Meaning

Enforced?

go 1.23.0

Minimum Go version required to build this module, and the language version for its code

Yes, strictly since 1.21

toolchain go1.23.4

Preferred toolchain when running go commands in this module

Only as a preference, never lower than go

Before 1.21 the go line was advisory and older compilers tried anyway. Since 1.21 it is a requirement: a Go 1.22 binary will not build a module that says go 1.23.0 unless it can switch to a newer toolchain.

The toolchain line is only written when it differs from what the go line implies, and only the main module's toolchain line counts; dependencies' toolchain lines are ignored.

How switching works

The go binary on your PATH is now a launcher as much as a compiler. When you run any go command in a module, it compares its own version with what the module requires and with the GOTOOLCHAIN setting, then either runs itself or downloads and runs another version.

Downloaded toolchains are ordinary modules (golang.org/toolchain at versions like v0.0.1-go1.23.4.linux-amd64), fetched through GOPROXY and verified against the checksum database like any dependency. They land in the module cache, so the second run is instant.

go version                  # the local binary, e.g. go1.22.6
cd services/billing
go version                  # go1.23.4 if go.mod asks for it
go env GOTOOLCHAIN

GOTOOLCHAIN values

GOTOOLCHAIN controls this behaviour. You can set it as an environment variable or persist it with go env -w.

Value

Behaviour

auto (default, same as local+auto)

Use the local toolchain unless the module needs a newer one, then download it

local

Always use the local binary; fail if the module needs newer

go1.23.4

Always use exactly that version, downloading if needed

go1.23.4+auto

Use at least that version, newer if the module requires it

path / go1.23.4+path

Like auto, but only look for toolchains on PATH, never download

With GOTOOLCHAIN=local, an old binary in a newer module fails with a clear message:

go: go.mod requires go >= 1.23.0 (running go 1.22.6; GOTOOLCHAIN=local)

That message is the single most common question we got during the migration. It is the system working: either upgrade the local Go, or allow switching.

Changing versions in a module

Use the go command to edit the lines rather than editing by hand, because it also updates requirements consistently:

go get go@1.23.0              # raise the minimum
go get toolchain@go1.23.4     # set the preferred toolchain
go mod edit -toolchain=none   # drop the toolchain line

Raising the go line is a breaking change for anyone depending on your module, since their builds now require that version. For libraries, keep the go line as low as your code allows and use toolchain for what you build and test with. For applications, both can follow your release cadence.

go get on a dependency that requires a newer go version also raises your go line. Read the diff of go.mod in every dependency update for that reason.

CI settings

In CI you want reproducible builds and predictable downloads.

  • Let the module decide. Install any recent Go and leave GOTOOLCHAIN at auto. The job uses exactly what go.mod says. Cache the module cache directory so toolchain downloads happen once.

  • Or install the exact version. Setup actions such as actions/setup-go accept go-version-file: go.mod. Pair this with GOTOOLCHAIN=local so a mismatch fails the job instead of silently downloading.

- uses: actions/setup-go@v5
  with:
    go-version-file: go.mod
- run: go version
  env:
    GOTOOLCHAIN: local
- run: go test ./...
  env:
    GOTOOLCHAIN: local

We chose the second for release builds because the build image is scanned and signed, and we did not want a different compiler fetched at build time. Developer laptops stay on auto.

Restricted networks

If GOPROXY points at an internal proxy, toolchain modules must be available there too. Most module proxies cache golang.org/toolchain like any module, but check yours. In fully offline environments set GOTOOLCHAIN=local or path and install toolchains through your normal artifact process. GOTOOLCHAIN=path is handy when you pre-install versions as go1.22.6 and go1.23.4 binaries on PATH.

When gvm still helps

gvm installs Go versions under ~/.gvm and switches by editing PATH, GOROOT and optionally GOPATH:

gvm install go1.20.14 -B     # -B uses a binary release instead of building
gvm use go1.20.14 --default
gvm list

It still earns its place in a few situations:

Situation

Why toolchain switching is not enough

Modules whose go line is below 1.21

Switching only goes up; an old project might break on a new compiler's vet or behaviour changes

Pre-modules GOPATH projects

gvm's pkgsets give each project its own GOPATH

Testing your code on many old Go versions locally

Easier to flip a shell between versions

Teams on mixed shells with existing gvm scripts

Migration cost may not be worth it yet

For the testing case there is also Go's own lightweight wrapper, which needs no extra tool:

go install golang.org/dl/go1.20.14@latest
go1.20.14 download
go1.20.14 test ./...

Each wrapper binary installs its SDK under ~/sdk/ and runs it on demand. For most teams that covers what gvm used to be needed for.

Our migration steps

  1. Installed one recent Go on laptops (Homebrew or the official installer), removed gvm's lines from shell startup files.

  2. Ran go get toolchain@go1.23.4 in each service and committed the go.mod changes.

  3. Switched release builds to go-version-file plus GOTOOLCHAIN=local.

  4. Confirmed the internal module proxy served golang.org/toolchain.

  5. Kept two legacy services on gvm until their go line was raised past 1.21.

Common mistakes

Mistake

Why it hurts

Do this instead

Bumping the go line in a library to match your laptop

Forces every consumer onto that version

Keep go minimal, use toolchain

GOTOOLCHAIN=local on laptops

Every newer module fails to build

Use auto locally, local in release CI

Ignoring go.mod diffs on dependency updates

go line quietly moves up

Review go and toolchain changes

Internal proxy without toolchain modules

Downloads fail with not found errors

Allow golang.org/toolchain or use path

Keeping gvm's GOROOT export after migrating

Conflicts with the switched toolchain

Remove gvm init from shell files

Key takeaways

  • Since Go 1.21, go in go.mod is a hard minimum and toolchain is a preference.

  • The go command downloads and runs the right toolchain when GOTOOLCHAIN allows it.

  • Use auto for development, local with an exact install for signed release builds.

  • Toolchains come through GOPROXY and the checksum database, so mirror them if you run a proxy.

  • Keep gvm or golang.org/dl wrappers for pre-1.21 modules and multi-version testing.

References