Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc/install: update “Test your installation” step to be agnostic to module mode #37042

Closed
tkl4230 opened this issue Feb 5, 2020 · 16 comments
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tkl4230
Copy link

tkl4230 commented Feb 5, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.7 darwin/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxxx/Library/Caches/go-build"
GOENV="/Users/xxxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xxxx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5k/x27nkdh9605dcjwmgmxbdr0c0000gn/T/go-build407033626=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I tried to create a go environment and proceeded according to the tutorial.

https://golang.org/doc/install?download=go1.13.7.darwin-amd64.pkg

Do you need go mod init before go build??
or execute go build hello.go.

$ pwd
/Users/xxxx/go/src/hello
$ ls
hello.go
$ go build
go: cannot find main module; see 'go help modules'

$ cat hello.go
package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}
@gopherbot gopherbot added this to the Unreleased milestone Feb 5, 2020
@ianlancetaylor ianlancetaylor changed the title x/website: Sample code fails cmd/go: Sample code fails Feb 5, 2020
@ianlancetaylor
Copy link
Member

This is happening because you have the environment variable GO111MODULE=on. That is telling the go tool that you will always be building in module mode. The go tool is complaining because it can't find a go.mod file for your program.

@bcmills @jayconrod We need a better error message here, or different behavior.

@ianlancetaylor ianlancetaylor changed the title cmd/go: Sample code fails cmd/go: confusing error with GO111MODULE=on Feb 5, 2020
@ianlancetaylor ianlancetaylor modified the milestones: Unreleased, Go1.15 Feb 5, 2020
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 5, 2020
@bcmills
Copy link
Contributor

bcmills commented Feb 5, 2020

@ianlancetaylor, do you have a specific suggestion? cannot find main module seems pretty unambiguous, and at this point in time we don't expect Go users to get very far without learning the basics of modules.

@bcmills
Copy link
Contributor

bcmills commented Feb 5, 2020

The issue as originally reported seems like a documentation problem: How to Write Go Code has been updated to include the necessary go mod init step, but users will typically read and follow the Test your installation step before they get to How to Write Go Code.

Probably we should suggest testing the installation using go build hello.go (which works regardless of the GO111MODULE setting) instead of just go build.

@bcmills bcmills changed the title cmd/go: confusing error with GO111MODULE=on doc/install: update “Test your installation” step to be agnostic to module mode Feb 5, 2020
@bcmills bcmills added Documentation Issues describing a change to documentation. modules NeedsFix The path to resolution is known, but the work has not been done. labels Feb 5, 2020
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 5, 2020
@bcmills
Copy link
Contributor

bcmills commented Feb 5, 2020

Heh, the “workspace” link in that section is broken too. (It uses a #Workspaces anchor that no longer exists.)

@tkl4230
Copy link
Author

tkl4230 commented Feb 5, 2020

I did not notice GO111MODULE = on.

I know that the default value is auto.
https://golang.org/doc/go1.13#modules

Previously, when I installed another version of Go, I set GO111MODULE = on, but this time, I did not set GO111MODULE = on myself after installing ...

Is it possible that the values from the previous installation are cached?
Is there any way to change the settings other than go env -w GO111MODULE = on?

@ianlancetaylor
Copy link
Member

@bcmills Think about what this is like for someone who knows nothing. Maybe people have to learn the basics of modules, but they can only do that if we help them. For a beginner to Go, "cannot find main module" means nothing. Better might be something like

cannot determine module because no go.mod file found; see "go help modules"

and, at least until module mode is the default,

(running in module mode because environment variable GO111MODULE=on)

And then "go help modules" (if that is indeed the right link) could use some cleanup as it is written from the perspective of someone who understands GOPATH.

@ianlancetaylor
Copy link
Member

@tkl4230 Yes, if you used go env -w then those values are cached. You can remove the setting with go env -u.

You can also set the environment variable for just one session using your shell, typically

export GO111MODULE=on

@tkl4230
Copy link
Author

tkl4230 commented Feb 5, 2020

@ianlancetaylor
Thank you for your reply.
I understand.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/217840 mentions this issue: doc/install.html: streamline the “Test your installation” step and make it module-agnostic

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/217877 mentions this issue: content/static/doc: describe GOPATH, 'go clean', and 'go env -u'

gopherbot pushed a commit that referenced this issue Feb 5, 2020
…ke it module-agnostic

In CL 199417, we updated “How to Write Go Code” to give a basic
introduction to modules and to include module-mode commands.
However, most new users will end up reading “Getting Started”
(doc/install.html) before “How to Write Go Code”, and we forgot to
update the handful of commands there for module mode.

Before this change, the “Test your installation” section also covered
quite a few operations beoyond merely testing the installation: it
included setting up a GOPATH, building a binary, and installing and
cleaning binaries. Those are valuable operations to learn, but they
arguably belong in “How to Write Go Code”, not “Test your
installation” — and having all that extra detail in the install
instructions may well discourage folks from further essential reading.

Rather than updating all of those operations here, I've removed them.
A companion CL will update “How to Write Go Code” to ensure that it
mentions GOPATH (as the location of the module cache and the default
install location for binaries) and 'go clean -i'.

Updates #37042

Change-Id: I157f21ccbe3896575fa1115dc821abf6c71ed15e
Reviewed-on: https://go-review.googlesource.com/c/go/+/217840
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tyler Bui-Palsulich <tbp@google.com>
@bcmills
Copy link
Contributor

bcmills commented Feb 5, 2020

I think that even because no go.mod file found would be confusing at this point in the flow: nothing in the “Getting Started” doc describes what a go.mod file is or how to create one, so “go.mod file” is nearly as mysterious as main module.

Similarly, GO111MODULE=on implies that the user explicitly set that variable at some point, so they probably have at least seen an introduction to using modules. So I'm not sure that detail would be helpful to beginners either.

We certainly do need to clean up go help modules to make it more approachable, though. (That is #33637.)

@ianlancetaylor
Copy link
Member

Can we at least have the error message point people to "go help modules" (if that is the best place)?

I don't really agree that "no go.mod file" is nearly as mysterious; at least it tells you exactly what is missing, and gives you a starting point for progress.

@bcmills
Copy link
Contributor

bcmills commented Feb 5, 2020

Can we at least have the error message point people to "go help modules" (if that is the best place)?

The error text already ends with: see 'go help modules'.

@ianlancetaylor
Copy link
Member

Oh, right, sorry.

gopherbot pushed a commit to golang/website that referenced this issue Feb 6, 2020
Plus some additional minor cleanup:

- Set PATH using a command that does not depend on GOBIN or GOPATH
  being set.

- Remove unusual whitespace from example output.

- Add Go 1.14 'go install' output to help clarify what happens when we
  need to download a module.

Updates golang/go#37042

Change-Id: I1bfb4ba38ccefa2b95be309dd465e3523895c1b6
Reviewed-on: https://go-review.googlesource.com/c/website/+/217877
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/218217 mentions this issue: content/static/doc: escape template brackets in code.html

gopherbot pushed a commit to golang/website that referenced this issue Feb 6, 2020
I forgot to escape them in CL 217877, and the TryBots don't currently
catch template errors in HTML docs.

Updates golang/go#37042
Updates golang/go#37072

Change-Id: Ia7b82a9c9b85914f224c04050bfbe3747d5a3acc
Reviewed-on: https://go-review.googlesource.com/c/website/+/218217
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@bcmills
Copy link
Contributor

bcmills commented Feb 6, 2020

This should now be fixed in http://tip.golang.org/doc/install: the “Test your installation” instructions are now module-agnostic (and more concise), and the descriptions of GOPATH and go install now occur after the introduction to modules in the new-user flow.

@bcmills bcmills closed this as completed Feb 6, 2020
@golang golang locked and limited conversation to collaborators Feb 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants