Go install changes in 1.16

In releases prior to 1.16 the following works.

  1. mkdir -p $(go env GOPATH)/src/mycode/
  2. cd $(go env GOPATH)/src/mycode/
  3. create code.go (empty main is fine)
  4. go install

Instead of $(go env GOPATH)/bin/mycode

I get

go: cannot find main module; see ‘go help modules’

I tried GO111MODULE=auto and off, got same error.

I read the release notes, and do not see anything directly related (might have missed something though).

If I run go mod tidy then go install it works. I understand we are moving to modules, but it seems the release notes are actually lacking the part saying its not optional (unless I am wrong).

Any thoughts?

Thanks.

Ron

I followed the Go 1.16 Release Notes instructions. I am unable to reproduce your issue.

Go 1.16 Release Notes

Modules

Module-aware mode is enabled by default, regardless of whether a go.mod file is present in the current working directory or a parent directory. More precisely, the GO111MODULE environment variable now defaults to on. To switch to the previous behavior, set GO111MODULE to auto.

$ dir
main.go
$ cat main.go
package main
func main(){}
$ go1.16 version
go version go1.16 linux/amd64

$ go1.16 env GO111MODULE
on
$ go1.16 install
go: cannot find main module; see 'go help modules'

$ export GO111MODULE=auto && go1.16 env GO111MODULE
auto
$ go1.16 install

$ export GO111MODULE=off && go1.16 env GO111MODULE
off
$ go1.16 install

$ export GO111MODULE=on && go1.16 env GO111MODULE
on
$ go1.16 install
go: cannot find main module; see 'go help modules'

$

Hi @petrus, thanks for that.

I made a mistake. I forgot to ‘export’.