how to run a go get command with certain environment values?

1.9k Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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.