Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src"

Tags:

go

I'm trying to install golint with the command: go get -u golang.org/x/lint/golint. And I think I got two problems:

go get: warning:      modules disabled by GO111MODULE=auto in GOPATH/src;     ignoring ../go.mod;     see 'go help modules'  package golang.org/x/lint/golint:  unrecognized import path "golang.org/x/lint/golint" (https fetch: Get https://golang.org/x/lint/golint?go-get=1: dial tcp 216.58.200.192:443: i/o timeout) 

I then try to install golang/tools, also failed...

package golang.org/x/tools: unrecognized import path "golang.org/x/tools" (https fetch: Get https://golang.org/x/tools?go-get=1: dial tcp 216.58.200.192:443: i/o timeout) 
like image 700
Dehua Li Avatar asked Jun 06 '19 10:06

Dehua Li


People also ask

Is Gopath required with Go modules?

As mentioned above, Go runtime still does use $GOPATH as a download directory of Go packages. To make the Google's saying correct, Go module does not entirely replace GOPATH , but replaces GOPATH for version control and package distribution.

What is GO111MODULE on?

GO111MODULE is an environment variable that can be set when using go for changing how Go imports packages. One of the first pain-points is that depending on the Go version, its semantics change.

Is Gopath deprecated?

Since 1.12 version Go modules is enabled by default and the GOPATH will be deprecated in 1.13 version. For those who are getting started with Go 1.12, the installation and set up goes will be as follows.

How to fix red imports from Go modules?

Make sure Go Modules integration is enabled in settings (Preferences / Settings | Go | Go Modules), and GOPATH indexing is disabled (Preferences / Settings | Go | GOPATH | Index entire GOPATH). As soon as I did this, the red imports went away and everything worked. Show activity on this post.

How to enable Go modules in Goland?

Basically, enable go modules in GoLand via: Make sure Go Modules integration is enabled in settings (Preferences / Settings | Go | Go Modules), and GOPATH indexing is disabled (Preferences / Settings | Go | GOPATH | Index entire GOPATH). As soon as I did this, the red imports went away and everything worked.

How to fix Goland won't rewrite go MOD file?

Fix up your go.mod: the generated file contains module "outsidegopath", but we want something like module github.com/stevetarver/outsidegopath. This is a bit wonky - GoLand will try to rewrite go.mod and remove parts of the path. Repeat a couple times and it will stop trying.

How do I import a package that is not in Gopath?

Create your main.go file referencing a package that does not exist in your $GOPATH. Add that package to your imports. Using go get the GoLand way via vgo as described in the gif here: Click on the import package. Click on the red inspection bulb. Click on "Sync packages of ...". Open the embedded terminal. go get your import.


2 Answers

I ran this command

export GO111MODULE="on"  

and that worked for me...

like image 119
Victor.Uduak Avatar answered Sep 30 '22 12:09

Victor.Uduak


Also got this error when trying to work with vgo

Removing GOROOT (you don't need to explicitly set GOROOT, Modern versions of Go can figure it out on their own based on the location of the go binary that you run), updating my GOPATH and export GO111MODULE="on" resolved the issue.

GOPATH see in here

GOPATH may be set to a colon-separated list of paths inside which Go code, package objects, and executables may be found.

Set a GOPATH to use goinstall to build and install your own code and external libraries outside of the Go tree (and to avoid writing Makefiles).

like image 28
Effi Bar-She'an Avatar answered Sep 30 '22 13:09

Effi Bar-She'an