GO LANG Libs in usr/local/go or home/username/go?

2.5k Views Asked by At

I'm Ubuntu 21.04 user and I'm trying to use "github.com/golang/protobuf/protoc-gen-go/grpc" lib and I'm confused if my $GOPATH should be GOPATH=$HOME/go or GOPATH=usr/local/go. Because I installed my grpc into GOPATH=$HOME/go, but VSCODE could not find it, just libs in usr/local/go.

May seem obvious to be usr/local/go, but I see everywhere people using $GOPATH as GOPATH=$HOME/go.

1

There are 1 best solutions below

4
Luiz Portela On

The PATH to the go tool should be set. However, GOROOT doesn't need to be set and will be deterined by the go tool when it runs. GOPATH defaults to $HOME/go and doesn't need to be set unless you want to move it elsewhere. With Go Modules, GOPATH is only used to store downloaded/cached modules, compiled objects, and go install binaries. Your source can live in any directory underneath a go.mod file.