golangci-lint

Install

CI installation

Most installations of golangci-lint are performed for CI.

It's important to have reproducible CI: don't start to fail all builds at the same time. With golangci-lint this can happen if you use option --enable-all and a new linter is added or even without --enable-all when one upstream linter is upgraded.

IMPORTANT: It's highly recommended installing a specific version of golangci-lint available on the releases page.

GitHub Actions

We recommend using our GitHub Action for running golangci-lint in CI for GitHub projects.

It's fast and uses smart caching inside, and it can be much faster than the simple binary installation.

Log output of the action

Also, the action creates GitHub annotations for found issues (you don't need to dig into build log to see found by golangci-lint issues):

GitHub annotations of the action

Other CI

Here is the other way to install golangci-lint:

# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.0
# or install it into ./bin/
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.62.0
# In Alpine Linux (as it does not come with curl by default)
wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.62.0
golangci-lint --version

It is advised that you periodically update the version of golangci-lint as the project is under active development and is constantly being improved. For any problems with golangci-lint, check out recent GitHub issues and update if needed.

Local Installation

Packaging status

Binaries

# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.0
golangci-lint --version

On Windows, you can run the above commands with Git Bash, which comes with Git for Windows.

Linux

Golangci-lint is available inside the majority of the package managers.

macOS

Brew

Note: brew can use a non-expected version of Go to build the binary, so we recommend either using our binaries or be sure of the version of Go used to build.

You can install a binary release on macOS using brew:

brew install golangci-lint
brew upgrade golangci-lint

Note: Previously we used a Homebrew tap. We recommend using official formula instead of the tap, but sometimes the most recent release isn't immediately available via Homebrew core due to manual updates that need to occur from Homebrew core maintainers. In this case, the tap formula, which is updated automatically, can be used to install the latest version of golangci-lint:

brew tap golangci/tap
brew install golangci/tap/golangci-lint

MacPorts

It can also be installed through MacPorts The MacPorts installation mode is community driven, and not officially maintained by golangci team.

sudo port install golangci-lint

Windows

Chocolatey

You can install a binary on Windows using chocolatey.

choco install golangci-lint

Scoop

You can install a binary on Windows using scoop.

scoop install main/golangci-lint

The scoop package is not officially maintained by golangci team.

Docker

docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.62.0 golangci-lint run -v

Preserving cache between consecutive runs:

docker run --rm -v $(pwd):/app -v ~/.cache/golangci-lint/v1.62.0:/root/.cache -w /app golangci/golangci-lint:v1.62.0 golangci-lint run -v

Colored output:

docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.62.0 golangci-lint run -v

Install from Sources

Such go install/go get or "tools pattern" installations aren't guaranteed to work.

We recommend using binary installation.

Those installations aren't recommended because of the following points:

  1. Those installations are compiling golangci-lint locally, the Go version used to build will depend on your local Go version.
  2. Some users use -u flag for go get, which upgrades our dependencies. Resulting binary was not tested and is not guaranteed to work.
  3. When using "tools pattern", the dependencies of a tool can modify the dependencies of another. Resulting binary was not tested and is not guaranteed to work.
  4. We've encountered issues with Go modules hashes due to unexpected recreation of dependency tags.
  5. go.mod replacement directives don't apply transitively. It means a user will be using patched version of golangci-lint if we use such replacements.
  6. It allows installation from main branch which can't be considered stable.
  7. It's slower than binary installation.
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0

Next

Quick Start: how to use golangci-lint.

Edit this page on GitHub