Skip to content
Latchkey

go env: Usage, Options & Common CI Errors

Inspect and configure the Go environment.

go env prints the effective Go environment. go env -w persists settings to a config file (the env file under os.UserConfigDir), which is how you set GOPROXY, GOFLAGS, or GOPRIVATE without exporting shell variables.

What it does

Prints all Go environment values, or just the ones you name. -w writes settings to the Go env file; -u unsets them. Real OS environment variables still override the env file at runtime.

Common usage

Terminal
go env                            # print everything
go env GOOS GOARCH GOPATH         # print specific values
go env -w GOFLAGS=-mod=mod        # persist a default flag
go env -w GOPROXY=https://proxy.example,direct
go env -u GOFLAGS                 # unset a persisted value

Common CI error: persisted GOFLAGS surprises the build

A go env -w GOFLAGS=... set on a self-hosted runner silently applies to every later job (e.g. forcing -mod=mod or -mod=vendor), causing builds to behave differently than locally. Fix: prefer per-job environment variables over go env -w on shared runners, and audit with go env GOFLAGS; clear stale settings with go env -u GOFLAGS.

Options

FormEffect
go env <NAME>Print a value
-w NAME=valPersist a setting
-u NAMEUnset a persisted setting
-jsonJSON output

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →