-3

I want to use go modules, after a lot of searching, I just saw some website that said, enable go111module with this command:

GO111MODULE=on

But it's not a path variable, it does not even exist on my pc, so it shows me

GO111MODULE is not recognized as an internal or external command, operable 
program, or batch file.

Some people said it's enabled by default on GO v1.16 but it's not working for me, How do I understand it's not working?

I use:

go mod init

and

go get <some_packages>

It adds the new package to my go.mod but my code can't recognize it and I have an "Unresolved dependency" error in my go.mod file.

I use Goland to solve my problem using their GUI's and it solved my problem but their settings just work on the current project and don't work globally.

What can I do? (I'm a Windows 10 user, Go version 1.16)

Answer (Update):

Set a path variable like this by yourself:

I can't activate GO111MODULE

After that, run the command:

go env

You will have this line at first line:

set GO111MODULE=on
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Arsham Arya
  • 1,461
  • 3
  • 17
  • 25
  • 2
    "Some people said it's enabled by default on GO v1.16 but I'm sure it's not!" -- Well, it is on by default. You can read this in the [official Go 1.16 release notes](https://golang.org/doc/go1.16#go-command). Why do you think it's not? – Jonathan Hall May 05 '21 at 09:08
  • 3
    What actual problem are you trying to solve? – Jonathan Hall May 05 '21 at 09:09
  • 1
    @Flimzy excuse me because I didn't say my problem well. Actually, it's not "on" because I make it on with Goland Settings and it starts working and recognizing packages. I'm trying to find a way to enable go modules for all of my projects not for every project and not just with Goland settings. – Arsham Arya May 05 '21 at 11:44
  • Thank you for updating your question. Now it's a tiny bit closer to explaining your problem, but still not there. You say "I have an import error". WHAT error? – Jonathan Hall May 05 '21 at 11:47
  • @Flimzy Unresolved dependency in go.mod file. – Arsham Arya May 05 '21 at 11:56
  • Do not put answers in the question. Answers belong as answers. – Jonathan Hall May 08 '21 at 16:09
  • Also, that answer is wrong. 1. That's not a "path variable" (whatever that is). 2. It's unnecessary as we've already discussed, becuase on is the default for Go 1.16. – Jonathan Hall May 08 '21 at 16:09
  • Nobody doubts that your problem is real. However, the question is very _unclear_. This is why the question was closed. And all of that is completely irrelevant to the fact that answers _do not belong in questions_. – Jonathan Hall May 09 '21 at 09:32
  • 1
    @Flimzy I passed 2 complete days to solve this problem, I said two ways to solve this problem, You closed my question and it forced me to answer in an update because I wanted to help others don't waste their time on solving this problem like me. I edited this post a lot, to be more clear, but now It's so simple: """go get adds the new package to my go.mod but my code can't recognize it and I have an "Unresolved dependency" error in my go.mod file.""" – Arsham Arya May 09 '21 at 09:44
  • I don't think you're listening to what I'm saying. There's nothing wrong with your answer, per se. There's nothing wrong with your problem. – Jonathan Hall May 09 '21 at 10:14
  • The only problem is that you did not ask a clear question. If you can clarify your question, it can be reopened. Then you can answer it properly. – Jonathan Hall May 09 '21 at 10:15
  • Abusing the question to provide an answer is NOT a solution to an unclear question. – Jonathan Hall May 09 '21 at 10:15

1 Answers1

2

Yes its not a path variable. It is a go environmental variable. Yes is is available by default actually.

On your terminal, type

go env | grep "GO111MODULE"

That should show you what that variable is set to You can try the same with other go env variables eg GOPROXY, GOPRIVATE etc just to satisfy yourself.

The output GO111MODULE="" means it is on (since Go 1.16)

guettli
  • 25,042
  • 81
  • 346
  • 663
Onke
  • 103
  • 1
  • 8
  • It says: "'grep' is not recognized as an internal or external command" In my go env there is something like this: "set GO111MODULE= " and "set GOMOD=NUL", in front of "GO111MODULE=" there is just empty space. – Arsham Arya May 05 '21 at 12:03