-1

When I use go get command:

sudo go get -u github.com/golang/dep/cmd/dep

My GOPATH is:

GOPATH="/home/hadoop/gopath"

and i found go get will create a new directory which named "go" in /home,and the dep package is in it, I want to know why not in GOPATH but to create a new directory?

Smallnine
  • 165
  • 7

3 Answers3

5

Because you are using sudo, the environment variables are not the same as the ones you see as yourself (your user).

You can, for example, use: sudo --preserve-env go get -u github.com/golang/dep/cmd/dep but likely you will have problems with permissions and whatnot.

Better idea would be to just run go get without sudo - if the GOPATH is in your home directory I don't see a point to use sudo in the first place.

matiit
  • 7,969
  • 5
  • 41
  • 65
1

Refer to this How to keep environment variables when using sudo

So I believe the env is not set when you use sudo.

You can check GOPATH's value using this go env and sudo go env

Ankit Deshpande
  • 3,476
  • 1
  • 29
  • 42
-2

I have finished, if we do not use sudo , it will download to GOPATH, though I don't know why

Smallnine
  • 165
  • 7