Maximum toolchain version

Hello,

I have some projects that are mainly run on RHEL 6 with a 2.6.32 Linux kernel. I’d like to set a maximum toolchain of 1.23.12 to produce compatible binaries.

It seems that the go and toolchain directives are more designed at being minimal versions than maximum versions. Do something exist to limit ?

I use (and it works):

$ go mod init go.vbcy.org/mymodule
$ cat go.mod
module go.vbcy.org/mymodule

go 1.25.5
$ go mod tidy
go: finding module for package github.com/gofrs/flock
go: found github.com/gofrs/flock in github.com/gofrs/flock v0.13.0
$ go get go@1.23.12
go: downgraded go 1.25.5 => 1.23.12
go: downgraded github.com/gofrs/flock v0.13.0 => v0.12.1
go: downgraded golang.org/x/sys v0.37.0 => v0.35.0
$ go mod tidy
$ CGO_ENABLED=0 GOTOOLCHAIN=go1.23.12 go build
$ go version mymodule
mymodule: go1.23.12

Is there a way not to run go mod tidy twice ?

If I run everything with GOTOOLCHAIN=go1.23.12 or the actual manually downloaded binary of go1.23.12 it will either try to download a 1.24 toolchain or fail the automatic version resolver.

go: finding module for package github.com/gofrs/flock
go: toolchain upgrade needed to resolve github.com/gofrs/flock
go: github.com/gofrs/flock@v0.13.0 requires go >= 1.24.0 (running go 1.23.12; GOTOOLCHAIN=go1.23.12)
go: finding module for package github.com/gofrs/flock
go: toolchain upgrade needed to resolve github.com/gofrs/flock
go: github.com/gofrs/flock@v0.13.0 requires go >= 1.24.0; switching to go1.24.11
go: downloading go1.24.11 (linux/amd64)

go mod edit -toolchain go1.23.12 does not stay in place: go.mod get automatically updated as soon as GOTOOLCHAIN is not set