Where is a good location for $GOPATH?

go

Solution

$GOPATH can really be any location you choose (with a few exceptions), so long as the compiler knows where to find it. If you change it just make sure you update the path with

`export GOPATH=/path/to/gopath`

My personal preference is to keep the $GOPATH separate from my code unless I'm writing a package which is meant to be imported via `go get <repo path>`, in which case I'll write the code in

`$GOPATH/src/<repo path>`

which is the standard location that the package gets stored when you use `go get <repo path>`

Problem

I'm working on a project in Go, which requires several external libraries, like a MySQL driver, an image manipulation library, etc. Right now, I have `$GOPATH` set to /usr/lib/go/src, which puts any downloaded packages in /usr/lib/go/src/src, which obviously doesn't seem right. If I set `$GOPATH` to /usr/lib/go, I get an error saying that `$GOPATH` can't be set to the same directory as `$GOROOT`. So should I put `GOPATH=/path/to/my/project/lib` in my build.sh, and when I commit to my git repo, put lib/ in my .gitignore? I realize this is probably a silly question. It works fine as it is now, I'm just wondering if this is bad practice.

Original source