I have set GOPATH and GOROOT in ~/.bashrc as:
export GOROOT=/usr/lib/go-1.10
export GOPATH=/home/user/go/pkg
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
and whenever I try to build with go build main.go I am getting.
main.go:4:2: cannot find package "google.golang.org/grpc/examples/grpcdemo/pb" in any of: /usr/lib/go-1.10/src/google.golang.org/grpc/examples/grpcdemo/pb (from $GOROOT) /home/user/go/src/google.golang.org/grpc/examples/grpcdemo/pb (from $GOPATH)
The question is why is looking inside home/user/go/src
as I have set the GOPATH to /home/user/go/pkg
. So, I have expected package inside/home/user/go/pkg/src/google.golang.org/grpc/examples/grpcdemo/pb
. Shouldn't it be looking inside /home/user/go/pkg
?
Probably should have
export GOPATH=/home/user/go
export PATH=$GOPATH/bin:$PATH
unset GOROOT
just to be safe )Run $ go env
and check if the output contains the followings or not:
GOPATH="/home/user/go"
GOROOT="/usr/local/go"
If not, then use like bellow in your ~/.bashrc
file
export GOPATH=$HOME/go
# No need to set GOROOT since it is set /usr/local/go by default
export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
Now run $ source ~/.bashrc
in bash. That's it.