Golang命令go env

月圆星繁 · · 2870 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。


  • go env :查看终端运行环境

PS H:\go_workspace> go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=H:\go_workspace
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=E:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=E:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build672771602=/tmp/go-build -gno-record-gcc-switches
  • go help env :查看 go env 帮助命令

PS H:\go_workspace> go help env
usage: go env [-json] [-u] [-w] [var ...]

Env prints Go environment information.

By default env prints information as a shell script
(on Windows, a batch file). If one or more variable
names is given as arguments, env prints the value of
each named variable on its own line.

The -json flag prints the environment in JSON format
instead of as a shell script.

The -u flag requires one or more arguments and unsets
the default setting for the named environment variables,
if one has been set with 'go env -w'.

The -w flag requires one or more arguments of the
form NAME=VALUE and changes the default settings
of the named environment variables to the given values.

For more about environment variables, see 'go help environment'.
  • go env xxx :查看指定配置

PS H:\go_workspace> go env GOPATH
H:\go_workspace
  • go env -json : 以json格式输出配置

PS H:\go_workspace> go env -json
{
        "AR": "ar",
        "CC": "gcc",
        "CGO_CFLAGS": "-g -O2",
        "CGO_CPPFLAGS": "",
        "CGO_CXXFLAGS": "-g -O2",
        "CGO_ENABLED": "1",
        "CGO_FFLAGS": "-g -O2",
        "CGO_LDFLAGS": "-g -O2",
        "CXX": "g++",
        "GCCGO": "gccgo",
        "GO111MODULE": "on",
        "GOARCH": "amd64",
        "GOBIN": "",
        "GOCACHE": "C:\\Users\\Administrator\\AppData\\Local\\go-build",
        "GOENV": "C:\\Users\\Administrator\\AppData\\Roaming\\go\\env",
        "GOEXE": ".exe",
        "GOFLAGS": "",
        "GOGCCFLAGS": "-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\go-build952984822=/tmp/go-build -gno-record-gcc-switches",
        "GOHOSTARCH": "amd64",
        "GOHOSTOS": "windows",
        "GOINSECURE": "",
        "GOMOD": "NUL",
        "GONOPROXY": "",
        "GONOSUMDB": "",
        "GOOS": "windows",
        "GOPATH": "H:\\go_workspace",
        "GOPRIVATE": "",
        "GOPROXY": "https://goproxy.cn,direct",
        "GOROOT": "E:\\go",
        "GOSUMDB": "sum.golang.org",
        "GOTMPDIR": "",
        "GOTOOLDIR": "E:\\go\\pkg\\tool\\windows_amd64",
        "PKG_CONFIG": "pkg-config"
}
PS H:\go_workspace>
  • go env -w xxx : 设置env

PS H:\go_workspace> go env -w GO111MODULE=on
  • go env -u GOPROXY : 取消env配置

PS H:\go_workspace> go env -u GOPROXY

在vscode中报错:

H:\go_workspace> go env -w GOPROXY=https://goproxy.cn,direct
go env -w: arguments must be KEY=VALUE: invalid argument: direct

在win下的cmd中执行成功:

H:\go_workspace>go env -w GOPROXY=https://goproxy.cn,direct


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:月圆星繁

查看原文:Golang命令go env

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2870 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传