Skip to content

Instantly share code, notes, and snippets.

@creachadair
Last active November 24, 2024 23:47
Show Gist options
  • Save creachadair/2d4e5465f9bb8327aa2d736cc9afb332 to your computer and use it in GitHub Desktop.
Save creachadair/2d4e5465f9bb8327aa2d736cc9afb332 to your computer and use it in GitHub Desktop.
Installing a Go toolchain with a GOEXPERIMENT set

Installing a Go Toolchain with GOEXPERIMENT

(see also: https://github.com/creachadair/misctools/blob/main/scripts/install-go.sh)

Go allows the definition of named, experimental features, which are established by setting GOEXPERIMENT in the environment. While some of these features are available at runtime, some must be enabled when building the toolchain itself. An example of the latter is the cacheprog experiment (as of August 2024).

To enable such an experiment:

  1. Download a source distribution of Go.
  2. Unpack the distribution and cd go/src.
  3. Set GOEXPERIMENT to a comma-separated list of experiments and run ./make.bash.

For example:

curl -sL https://go.dev/dl/go1.23.0.src.tar.gz | tar -x
cd go/src
GOEXPERIMENT=cacheprog ./make.bash

Note

Building from source requires a bootstrap to be installed. The easiest way to do so is to install a binary distribution of the toolchain somewhere in your $PATH. The pre-built binary installations do not enable experiments by default, but you can use them to bootstrap one that does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment