英文:
how to run a go get command with certain environment values?
问题
当GOPROXY='direct'
时,我想运行一个go get命令。我尝试在VS Code终端中运行以下命令:
GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
但是我遇到了以下错误:
GOPROXY=direct : 无法将“GOPROXY=direct”识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
At line:1 char:1
+ GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (GOPROXY=direct:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
我还尝试了以下命令:
go env set GOPROXY='direct'
但是当我运行go env
命令时,GOPROXY
的值仍然是这样的:GOPROXY=https://proxy.golang.org,direct
。我还尝试在Windows环境变量中定义一个GOPROXY变量,并将其值设置为direct
,但它也无法完成任务。
英文:
I want to run a go get command when GOPROXY='direct'
, I've tried to run this command using the VS code terminal:
GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
but I'm getting this error:
GOPROXY=direct : The term 'GOPROXY=direct' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ GOPROXY='direct' go get go.mongodb.org/mongo-driver/mongo
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (GOPROXY=direct:String) [], CommandNotFoundEx
ception
+ FullyQualifiedErrorId : CommandNotFoundException
I've also tried:
go env set GOPROXY='direct'
but when I run go env
command the GOPROXY
value is still like this GOPROXY=https://proxy.golang.org,direct
and I also tried to define a GOPROXY variable in the windows environment variable and giving it the value of direct
but it also failed to do the job.
答案1
得分: 2
请确保你的VSCode终端是bash
终端,而不是CMD或Powershell。
在CMD或Powershell中,语法var=xxx cmd
将无法正确解释为:设置一个变量并执行一个命令,继承其环境变量,包括已设置的变量。
英文:
Make sure your VSCode terminal is a bash
one, not a CMD or Powershell.
In a CMD or Powershell, the syntax var=xxx cmd
would not be correctly interpreted as: set a variable and execute a command inheriting its environment variables, including the one set.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论