You’ve most likely simply tried to initialise a brand new Go module, and obtained the next error:
go mod init: modules disabled by GO111MODULE=off; see 'go assist modules'
This often occurs after working a command like:
go mod init github.com/<person>/<repo>
What’s GO111MODULE?
From Go model 1.11, the way in which to cope with modules was revamped.
Beforehand, it was required that you simply place all of your Go code below a $GOPATH.
Which many Go builders didn’t very like, because it appeared chaotic at greatest.
Additionally, having a package deal administration/module administration resolution is a lot extra productive, and manageable.
Answer 1:
You may at all times simply go and alter the off
to on
as an setting variable and also you’d be good to go!
export GO111MODULE="on"
This might lead to a profitable module being created after attempting the earlier command that resulted within the error within the first place:
go: creating new go.mod: module github.com/<person>/<repo>
Should you’re on Home windows, merely substitute export
with set
.
Answer 2:
For a extra direct method of attaining the identical as Answer 1 above, use Go on to replace the setting variable:
go env -w GO111MODULE=on
Answer 3:
It’s fairly potential that you’ve a go.mod
file below your $GOPATH/go.mod
location.
You must take away this file.
Keep in mind that since you’re utilizing Go 1.11 or newer, you need to use the go get
command outdoors of $GOPATH, so it’s now not required.