This question already has an answer here:
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?
</div>
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.
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
I have finished, if we do not use sudo , it will download to GOPATH, though I don't know why