我正在尝试构建一些go项目。从项目目录运行go build
会返回以下错误:
../../../github.com/getsentry/sentry-go/integrations.go:4:2: cannot find package "bufio" in any of:
/home/user/go/src/bufio (from $GOROOT)
($GOPATH not set. For more details see: 'go help gopath')
vendor/github.com/getsentry/raven-go/client.go:5:2: cannot find package "bytes" in any of:
/home/user/go/src/gitlab.com/company/bc_to_influx/vendor/bytes (vendor tree)
/home/user/go/src/bytes (from $GOROOT)
($GOPATH not set. For more details see: 'go help gopath')
vendor/github.com/getsentry/raven-go/client.go:6:2: cannot find package "compress/zlib" in any of:
/home/user/go/src/gitlab.com/company/bc_to_influx/vendor/compress/zlib (vendor tree)
/home/user/go/src/compress/zlib (from $GOROOT)
($GOPATH not set. For more details see: 'go help gopath')
../../../github.com/getsentry/sentry-go/client.go:4:2: cannot find package "context" in any of:
/home/user/go/src/context (from $GOROOT)
($GOPATH not set. For more details see: 'go help gopath')
vendor/github.com/getsentry/raven-go/client.go:7:2: cannot find package "crypto/rand" in any of:
/home/user/go/src/gitlab.com/company/bc_to_influx/vendor/crypto/rand (vendor tree)
/home/user/go/src/crypto/rand (from $GOROOT)
($GOPATH not set. For more details see: 'go help gopath')
,依此类推,获取项目所需的各种软件包。 出现了许多问题:
-
GOPATH被声明为“未设置”,而实际上它设置为“ / home / user / go”,正如我通过运行
go env
所看到的(顺便说一句,GOROOT设置为“ / home / user / go”,我认为这可能会造成一些麻烦,因为我了解GOPATH和GOROOT应该有所不同) -
go似乎在“ / home / user / go / src / bufio”中查找诸如bufio之类的软件包,而我希望它在“ / home / user / go / src / github”中进行搜索。 com / bufio”
一种解决方法是使用sudo go build
,它可以正常工作,但我想正确地解决此问题。对于root用户,将GOPATH设置为“ / root / go”,将GOROOT设置为“ / snap / go / 4762”。
我正在使用govendor,并且GO111MODULE设置为关闭。