Go 命令之 go env

Go About 1,907 words

查看运行环境

go env

输出

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\fendoudebb\AppData\Local\go-build
set GOENV=C:\Users\fendoudebb\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\Dev\gopath\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\Dev\gopath
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\Dev\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Dev\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\ZHANGB~1\AppData\Local\Temp\go-build738457106=/tmp/go-build -gno-record-gcc-switches

environment

GOARCHGOMODGOROOT等字段解释

go help environment

env

通过命令行设置Go运行环境

命令

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 GOPROXY

GOPATH

go env GOPATH

以JSON格式输出

go env -json

设置env

-w:将Golang编译的架构更改为arm

go env -w GOARCH=arm

取消设置env

-u:取消使用-w设置的env变量(还原为默认设置)

go env -u GOARCH
Views: 12,300 · Posted: 2019-04-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh