I'm using go modules as dependency management, and I'm having problem to install something like this:
go get -u github.com/go-critic/go-critic/...
the result from above was:
go: cannot find main module; see 'go help modules'
Edit: The original answer herein referred specifically to the state of the tooling in Go 1.11. Since the release of Go 1.12, this is no longer accurate. Please see this answer, and the ones it links to, for details of handling this situation in Go 1.12 and later.
If the GO111MODULE
var is set to on
, you have to be inside an initialized go module directory tree in order to use go get
, even if you're trying to get a tool rather than a new dependency. This is a known and heavily debated issue:
https://github.com/golang/go/issues/27643
https://github.com/golang/go/issues/24250
https://github.com/golang/go/issues/25922
The solution, short term, is to run GO111MODULE=off go get <tool>
. This explicitly disables the module support, even if you're in a module package currently, and forces it to only utilize your GOPATH.
Long-term, figuring out what the best solution is to support tool install via go get
(or another command, like go install
with a flag) is an ongoing area of discussion with
little in the way of established consensus as of yet. However, there's a PR open for Go 1.12 that, if accepted, will allow go get
to simply work while outside a module, even with GO111MODULE=on
set.