Local Installation (original) (raw)

Binaries

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

# or install it into ./bin/
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s v2.7.2

# In Alpine Linux (as it does not come with curl by default)
wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s v2.7.2

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.

Packaging status

Packaging status

macOS

Homebrew

Note: Homebrew can use an unexpected version of Go to build the binary, so we recommend either using our binaries or ensuring 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 the 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 MacPortsThe MacPorts installation mode is community-driven and not officially maintained by the 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

The Docker image is available on Docker Hub.

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

Colored output:

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

Preserving caches between consecutive runs:

docker run --rm -t -v $(pwd):/app -w /app \
--user <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi>i</mi><mi>d</mi><mo>−</mo><mi>u</mi><mo stretchy="false">)</mo><mo>:</mo></mrow><annotation encoding="application/x-tex">(id -u):</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">u</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span></span></span></span>(id -g) \
-v $(go env GOCACHE):/.cache/go-build -e GOCACHE=/.cache/go-build \
-v $(go env GOMODCACHE):/.cache/mod -e GOMODCACHE=/.cache/mod \
-v ~/.cache/golangci-lint:/.cache/golangci-lint -e GOLANGCI_LINT_CACHE=/.cache/golangci-lint \
golangci/golangci-lint:v2.7.2 golangci-lint run

Install from Sources

Warning

Using go install/go get, “tools pattern”, and tool command/directives installations aren’t guaranteed to work.
We recommend using binary installation.

These installations aren’t recommended because of the following points:

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

go tool usage recommendations