Skip to content

docs: go tool note #5549

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

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/src/docs/welcome/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,76 @@ These installations aren't recommended because of the following points:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{.LatestVersion}
```

<details>
<summary>`go tool` usage recommendations</summary>

We don't recommend using `go tool`.

But if you want to use `go tool` to install and run golangci-lint (once again we don't recommend that),
the best approach is to use a dedicated module or module file to isolate golangci-lint from other tools or dependencies.

This approach avoids modifying your project dependencies and the golangci-lint dependencies.

**⚠️ IMPORTANT ⚠️: You should never update golangci-lint dependencies manually.**

**Method 1: dedicated module file**

```sh
# Create a dedicated module file
go mod init -modfile=golangci-lint.mod <your_module_path>/golangci-lint
# Example: go mod init -modfile=golangci-lint.mod github.com/org/repo/golangci-lint
```

```sh
# Add golangci-lint as a tool
go get -tool -modfile=golangci-lint.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{.LatestVersion}
```

```sh
# Run golangci-lint as a tool
go tool -modfile=golangci-lint.mod golangci-lint run
```

```sh
# Update golangci-lint
go get -tool -modfile=golangci-lint.mod github.com/golangci/v2/golangci-lint/cmd/golangci-lint@latest
```

**Method 2: dedicated module**

```sh
# Create a dedicated directory
mkdir golangci-lint
```

```sh
# Create a dedicated module file
go mod init -modfile=tools/go.mod <your_module_path>/golangci-lint
# Example: go mod init -modfile=golangci-lint/go.mod github.com/org/repo/golangci-lint
```

```sh
# Setup a Go workspace
go work init . golangci-lint
```

```sh
# Add golangci-lint as a tool
go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint
```

```sh
# Run golangci-lint as a tool
go tool golangci-lint run
```

```sh
# Update golangci-lint
go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
```

</details>

## Next

[Quick Start: how to use `golangci-lint`](/welcome/quick-start/).
Loading