go-env
Print Go environment information
TLDR
Show all environment variables
Show a specific environment variable
Set an environment variable to a value
Reset an environment variable's value
SYNOPSIS
go env [variable ...]
PARAMETERS
variable
Specifies the name of a single environment variable to print. If no variable is provided, all defined variables are printed.
-json
Print the environment variables in JSON format.
-u
Print the value as a unix shell variable
-w
Modifies the environment variables to the next execution. (Requires argument) `go env -w GO111MODULE=on`
DESCRIPTION
The `go env` command is a tool within the Go programming language ecosystem used to display Go environment variables. These variables configure the Go build system and runtime, influencing aspects like compiler behavior, package search paths, and platform-specific settings. It is commonly used to diagnose build problems, verify Go installations, or configure build processes. The command provides a convenient way to inspect the environment without needing to manually examine shell variables or configuration files. By default, `go env` prints all defined variables, but it can also be used to retrieve the value of a specific variable by providing its name as an argument. The output format is generally a series of `key=value` pairs, suitable for use in scripts or other programs.
It can be used to easily identify locations of Go installation and GOPATH, where packages will be downloaded.
CAVEATS
The output of `go env` reflects the configuration at the time the command is executed. Changes to shell environment variables after Go is installed or while the command is executed might not be reflected in the `go env` output.
Modification with -w may not always work, and might be necessary to configure environment variables in the system.
EXAMPLES
go env: Display all Go environment variables.
go env GOPATH: Display the value of the GOPATH environment variable.
go env GOROOT: Display the value of the GOROOT environment variable.
go env -json: Display all Go environment variables in JSON format.
HISTORY
`go env` has been a part of the Go toolchain since the early versions of Go (1.0). It was introduced as a way to provide a consistent and reliable method for querying the Go environment configuration. Over time, its output and features have been refined to better suit the needs of Go developers, including adding options for JSON output and specifying particular variable values.
SEE ALSO
go(1)