Use go env to list all Go environment variables or go env VARNAME to view a specific one; set variables by exporting them in your shell or using go env -w VARNAME=value for persistent changes.
# View all variables
go env
# View a specific variable
go env GOPATH
# Set a variable persistently (survives restarts)
go env -w GOPROXY=https://proxy.golang.org,direct
# Set a variable for the current session only
export GOPATH=/home/user/go
The go env command reads from your shell environment, the GOENV file, and defaults defined in the Go toolchain. Changes made with go env -w are stored in $GOENV (typically ~/.config/go/env on Linux/macOS or %APPDATA%\go\env on Windows).