帮助文档:

    1. $ go help env
    2. usage: go env [-json] [-u] [-w] [var ...]
    3. Env prints Go environment information.
    4. By default env prints information as a shell script
    5. (on Windows, a batch file). If one or more variable
    6. names is given as arguments, env prints the value of
    7. each named variable on its own line.
    8. The -json flag prints the environment in JSON format
    9. instead of as a shell script.
    10. The -u flag requires one or more arguments and unsets
    11. the default setting for the named environment variables,
    12. if one has been set with 'go env -w'.
    13. The -w flag requires one or more arguments of the
    14. form NAME=VALUE and changes the default settings
    15. of the named environment variables to the given values.
    16. For more about environment variables, see 'go help environment'.

    查看更详细帮助文档:

    1. $ go help environment

    查看当前环境变量:

    1. $ go env --json

    获取某个环境变量的值:

    1. $ go env <NAME>

    改变环境变量的值:

    1. $ go env -w <NAME>=<VALUE>

    上述命令会更改默认设置,并记录在 Go 的环境配置文件,该文件存储在用户的配置目录中,可通过 os.UserConfigDir 函数获取。Windows 系统下路径可能为:

    1. C:\Users\<user_name>\AppData\Roaming\go\env

    通过 go env -w 设置的值不会覆盖系统设置的相关环境变量。

    常用的设置有:

    1. go env -w GOPROXY=https://goproxy.cn,direct
    2. go env -w GO111MODULE=on