Local Installation
Linux
Golangci-lint is available inside the majority of the package managers.
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-lintNote: 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-lintMacPorts
It can also be installed through MacPorts The MacPorts installation mode is community-driven and not officially maintained by the golangci team.
sudo port install golangci-lintWindows
Chocolatey
You can install a binary on Windows using chocolatey.
choco install golangci-lintScoop
You can install a binary on Windows using scoop.
scoop install main/golangci-lintThe 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 runColored output:
docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.7.2 golangci-lint runPreserving caches between consecutive runs:
docker run --rm -t -v $(pwd):/app -w /app \
--user $(id -u):$(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 runInstall 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:
- These installations compile golangci-lint locally. The Go version used to build will depend on your local Go version.
- Some users use the
-uflag forgo get, which upgrades our dependencies. The resulting binary was not tested and is not guaranteed to work. - When using the “tools pattern” or
toolcommand/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. - We’ve encountered issues with Go module hashes due to the unexpected recreation of dependency tags.
go.modreplacement directives don’t apply transitively. It means a user will be using a patched version of golangci-lint if we use such replacements.- It allows installation from the main branch, which can’t be considered stable.
- It’s slower than binary installation.
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2go tool usage recommendations
Warning
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.
Caution
You should never update golangci-lint dependencies manually.
Method 1: dedicated module file
# 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# Add golangci-lint as a tool
go get -tool -modfile=golangci-lint.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.2# Run golangci-lint as a tool
go tool -modfile=golangci-lint.mod golangci-lint run# Update golangci-lint
go get -tool -modfile=golangci-lint.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latestMethod 2: dedicated module
# Create a dedicated directory
mkdir golangci-lint# 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# Setup a Go workspace
go work init . golangci-lint# Add golangci-lint as a tool
go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint# Run golangci-lint as a tool
go tool golangci-lint run# Update golangci-lint
go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest