Repository: prometheus/prometheus (language: go)

Issue:
Build from source command doesn't work
### What did you do?

Followed the README to install Prometheus from source using: `GO111MODULE=on go install github.com/prometheus/prometheus/cmd/prometheus`

### What did you expect to see?

Prometheus being installed.

### What did you see instead? Under which circumstances?

The following compilation error:

```sh
$ GO111MODULE=on go install github.com/prometheus/prometheus/cmd/prometheus/...
/go/pkg/mod/github.com/prometheus/prometheus@v1.8.2-0.20220308163432-03831554a519/web/ui/doc.go:19:2: missing go.sum entry for module providing package github.com/shurcooL/httpfs/filter (imported by github.com/prometheus/prometheus/web/ui); to add:
        go get github.com/prometheus/prometheus/web/ui@v1.8.2-0.20220308163432-03831554a519
/go/pkg/mod/github.com/prometheus/prometheus@v1.8.2-0.20220308163432-03831554a519/web/ui/doc.go:20:2: missing go.sum entry for module providing package github.com/shurcooL/httpfs/union (imported by github.com/prometheus/prometheus/web/ui); to add:
        go get github.com/prometheus/prometheus/web/ui@v1.8.2-0.20220308163432-03831554a519
/go/pkg/mod/github.com/prometheus/prometheus@v1.8.2-0.20220308163432-03831554a519/web/ui/doc.go:21:2: missing go.sum entry for module providing package github.com/shurcooL/vfsgen (imported by github.com/prometheus/prometheus/web/ui); to add:
        go get github.com/prometheus/prometheus/web/ui@v1.8.2-0.20220308163432-03831554a519
```

### System information

Linux codespaces-787b6c 5.4.0-1074-azure #77~18.04.1-Ubuntu SMP Wed Mar 30 15:36:02 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

### Prometheus version

_No response_

### Prometheus configuration file

_No response_

### Alertmanager version

_No response_

### Alertmanager configuration file

_No response_

### Logs

_No response_


Discussion / hints:
Tried to reproduce this behavior in a containerized docker environment.

### What did you do?
1. Used **ubuntu:18.04** image.
2. Installed **Go**.
3. Installed **Nodejs**.
4. Installed **npm**.
5. Executed `GO111MODULE=on /usr/local/go/bin/go install github.com/prometheus/prometheus/cmd/prometheus@latest`.

Same steps were followed using **ubuntu:20.04** image, too.

### What did you expect to see?
Prometheus being installed.

### What did you see instead? Under which circumstances?

> go: downloading github.com/prometheus/prometheus v0.36.0
go: github.com/prometheus/prometheus/cmd/prometheus@latest (in github.com/prometheus/prometheus@v0.36.0):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.


### _UPDATE:_

The `go.mod` file contains the following:
> replace (
	k8s.io/klog => github.com/simonpasquier/klog-gokit v0.3.0
	k8s.io/klog/v2 => github.com/simonpasquier/klog-gokit/v3 v3.0.0
)

As stated [here](https://github.com/golang/go/issues/40276):
> If that module has a go.mod file, it must not contain directives that
would cause it to be interpreted differently if the module were the main
module. In particular, it must not contain replace or exclude
directives.

So, this error appears whenever a version _(@version)_ is specified.

If I try to execute `GO111MODULE=on /usr/local/go/bin/go install github.com/prometheus/prometheus/cmd/prometheus`, I get:
> go: 'go install' requires a version when current directory is not in a module
	Try 'go install github.com/prometheus/prometheus/cmd/prometheus@latest' to install the latest version

Hi there! I was able to get `GO111MODULE=on go install github.com/prometheus/prometheus/cmd/...` to work, but only when executed from the root of the cloned repository. Looking through the history of that bit of the documentation, I found [this conversation](https://github.com/prometheus/prometheus/pull/9098#discussion_r680405199), which confirms the issue. As was pointed out [later in that PR](https://github.com/prometheus/prometheus/pull/9098#issuecomment-905336834) by @fhemberger, `make build` is basically the exact same thing, so I think it would make sense to just remove `GO111MODULE=on go install github.com/prometheus/prometheus/cmd/...` as whole, or at least clarify where it has to be run.

cc @juliusv
Yeah, my understanding of Go modules is not current or deep enough to understand this case exactly, but just stating in the README.md right above that `go install` line that it needs to be executed from the checked-out repo's root is probably a decent way to go?
Yeah, sounds good to me.

Fix patch:
diff --git a/README.md b/README.md
index 3a1784f629c..6ca98143cbc 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,14 @@ To build Prometheus from source code, You need:
 * NodeJS [version 16 or greater](https://nodejs.org/).
 * npm [version 7 or greater](https://www.npmjs.com/).
 
-You can directly use the `go` tool to download and install the `prometheus`
+Start by cloning the repository:
+
+```bash
+git clone https://github.com/prometheus/prometheus.git
+cd prometheus
+```
+
+You can use the `go` tool to build and install the `prometheus`
 and `promtool` binaries into your `GOPATH`:
 
 ```bash
@@ -79,14 +86,10 @@ React UI unless it has been built explicitly using `make assets` or `make build`
 
 An example of the above configuration file can be found [here.](https://github.com/prometheus/prometheus/blob/main/documentation/examples/prometheus.yml)
 
-You can also clone the repository yourself and build using `make build`, which will compile in
-the web assets so that Prometheus can be run from anywhere:
+You can also build using `make build`, which will compile in the web assets so that
+Prometheus can be run from anywhere:
 
 ```bash
-mkdir -p $GOPATH/src/github.com/prometheus
-cd $GOPATH/src/github.com/prometheus
-git clone https://github.com/prometheus/prometheus.git
-cd prometheus
 make build
 ./prometheus --config.file=your_config.yml
 ```


Test patch: