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
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 valueCommon 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
| Form | Effect |
|---|---|
| go env <NAME> | Print a value |
| -w NAME=val | Persist a setting |
| -u NAME | Unset a persisted setting |
| -json | JSON output |