You’ve probably just tried to initialise a new Go module, and received the following error:
go mod init: modules disabled by GO111MODULE=off; see 'go help modules'
This usually happens after running a command like:
What is GO111MODULE?
From Go version 1.11, the way to deal with modules was revamped.
Beforehand, it was required that you place all your Go code under a $GOPATH.
Which many Go developers didn’t much like, as it seemed chaotic at best.
Also, having a package management/module management solution is so much more productive, and manageable.
You could always just go and change the
on as an environment variable and you’d be good to go!
This would result in a successful module being created after trying the previous command that resulted in the error in the first place:
go: creating new go.mod: module github.com/<user>/<repo>
If you’re on Windows, simply replace
For a more direct way of achieving the same as Solution 1 above, use Go directly to update the environment variable:
It’s quite possible that you have a
go.mod file under your
You should remove this file.
Remember that since you are using Go 1.11 or newer, you can use the
go get command outside of $GOPATH, so it’s no longer required.