How to Fix “go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src”

The go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src warning is raised when you encounter related to the Go module system and your GOPATH.

Starting from Go 1.16, Go modules are enabled by default, but your current setup seems to have GO111MODULE set to auto. When set to auto, Go uses the old GOPATH mode if the project is inside GOPATH/src and modules if the project is outside GOPATH/src.

To fix the warning, you have a couple of options.

Option 1: Enable Go modules explicitly

Set the GO111MODULE environment variable to on. This will enable Go modules explicitly, regardless of your project’s location.

export GO111MODULE=on

After setting this environment variable, you can run the go get command.

Option 2: Move your project outside of the GOPATH/src

If your project is inside the GOPATH/src directory, you can move it to another location outside of the GOPATH. This way, Go will automatically enable modules for your project.

After moving your project, make sure to run go mod init to initialize the Go module for your project if you haven’t done so already:

go mod init

Then, replace with your project’s import path.

By following either of these approaches, you should be able to resolve the warning message and use the Go modules effectively.

That’s it.

Leave a Comment