GOLand设置报错warning: go env -w GOPROXY=... does not override conflicting OS environm

GOLand设置报错warning: go env -w GOPROXY=... does not override conflicting OS environm,第1张

一般来说国内不能直接访问golang官方包:所以需要做个代理就是设置GOPROX环境变量

设置了Go语言的环境变量:
 

go env -w GO111MODULE=on

go env -w GOPROXY=https://goproxy.cn,direct

设置完后,在GoLand控制台执行go mod download在执行下载mod报错:

报错信息是连接不上官方网址,可是我明明走了代理不访问官方网址,走https://goproxy.cn的啊。开始查找原因。

打开cmd,用go env 命令查看:

C:\Users\Administrator>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 GOMODCACHE=C:\Users\Administrator\go\pkg\mod
set GONOPROXY=*.corp.example.com
set GONOSUMDB=*.corp.example.com
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPRIVATE=*.corp.example.com
set GOPROXY=https://goproxy.cn
set GOROOT=D:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build423114610=/tmp/go-build -gno-record-gcc-switches

然后在GoLand控制台执行go env:

C:\Users\Administrator\IdeaProjects\staff-profile>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 GOMODCACHE=C:\Users\Administrator\IdeaProjects\pkg\mod
set GONOPROXY=*.corp.example.com
set GONOSUMDB=*.corp.example.com
set GOOS=windows
set GOPATH=C:\Users\Administrator\IdeaProjects;C:\Users\Administrator\go
set GOPRIVATE=*.corp.example.com
set GOPROXY=direct
set GOROOT=D:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Administrator\IdeaProjects\staff-profile\go.mod
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\ADMINI~1\AppData\Local\Temp\go-build682176362=/tmp/go-build -gno-record-gcc-switches

两个GOPROXY的值不一样,在GoLand控制台的GOPROXY的值是direct,还是走官方默认的网址去下载依赖包。。

于是重新设置代理地址,当我在GoLand控制台设置代理时GoLand报错:

warning: go env -w GOPROXY=... does not override conflicting OS environment variable

后来找了很久原因,这是因为在环境变量中有这个值,在电脑的环境变量果然找到了这个之前装Go环境设置的值,把它删除,保存,重启GoLand后,在下面的界面重新设置:

然后在GoLand控制台设置:

go env -w GOPROXY=https://goproxy.cn,direct

然后就可以执行go mod download了。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/994118.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存