Use the go install golang.org/dl/go<version>@latest command to install specific Go versions, then switch between them using go version and go install.
# Install Go 1.21 and Go 1.23
go install golang.org/dl/go1.21@latest
go install golang.org/dl/go1.23@latest
# Switch to Go 1.21
go1.21 download
export GOROOT=$(go1.21 env GOROOT)
export PATH=$GOROOT/bin:$PATH
# Verify the active version
go version
Alternatively, set the GODEBUG environment variable to control runtime behavior for specific versions without changing the toolchain:
export GODEBUG=http2client=0,panicnil=1
go run main.go