Skip to content

Installing AST Metrics

AST Metrics is built in Golang and distributed as a single binary. It has no dependencies.

🚀 Quick Install

Choose your preferred method below.

Homebrew (Linux/MacOS)
brew install ast-metrics/tap/ast-metrics

Homebrew keeps the binary up to date: brew upgrade installs new releases.

JavaScript / TypeScript Project (npm)

On a JavaScript or TypeScript project, install AST Metrics like any other dev tool, so that its version lands in your lockfile:

npm install --save-dev ast-metrics
npx ast-metrics analyze src

Or without installing anything: npx ast-metrics analyze src. The package downloads the binary matching your platform on first run and caches it. npm is an official channel since v0.42.0.

Python Project (pip / pipx)

Run it without installing anything:

pipx run ast-metrics analyze src

Or add it to your project like any other dev tool, so that its version lands in your lockfile:

pip install ast-metrics
# or, with uv:
uv add --dev ast-metrics

ast-metrics analyze src

The PyPI package downloads the binary matching your platform on first run and caches it.

🪄 Automatic Install (Linux/MacOS/Windows)

Run the following command to download the latest version:

curl -fsSL https://install.ast-metrics.dev|sh

Then move the ./ast-metrics binary to a directory in your PATH (e.g. /usr/local/bin for Linux/MacOS).

Be careful when running scripts from the internet. Always check the content of the script before running it.

Debian / Ubuntu (.deb) and Fedora / RHEL (.rpm)

Each release ships .deb and .rpm packages for amd64 and arm64. Download the one for your platform from the latest release, then:

# Debian / Ubuntu
sudo dpkg -i ast-metrics_*_amd64.deb

# Fedora / RHEL
sudo rpm -i ast-metrics-*.x86_64.rpm
Linux (Manual)

Download the binary for your platform (run uname -m in your terminal to get your architecture):

MacOS (Manual)

Download the binary for your platform (run uname -m in your terminal to get your architecture):

  • arm64 (for Apple Silicon / M1 / M2)
  • amd64 (for Intel Macs)
Windows (Manual)

Download the executable:

Docker

No installation at all. Mount your project and run:

docker run --rm -v $(pwd):/src ghcr.io/ast-metrics/ast-metrics:latest analyze --report-html=/src/report /src

The image is published on each release for amd64 and arm64: ghcr.io/ast-metrics/ast-metrics.

🐘 PHP Project (Composer)

If you are working on a PHP project, you can install AST Metrics as a dev dependency via Composer. This is the recommended way for PHP developers as it manages the binary version for you.

composer require --dev ast-metrics/ast-metrics

Then you can run it using:

php vendor/bin/ast-metrics analyze .
Python Project (pip)

On a Python project, the same package exists on PyPI:

pip install ast-metrics          # or: uv add --dev ast-metrics, poetry add --group dev ast-metrics
ast-metrics analyze src

Or without installing anything: pipx run ast-metrics analyze src. A pre-commit hook is available too. The binary is downloaded on first run and cached.

Go Install

If you have Go and a C compiler installed (CGO is required by the tree-sitter parsers):

go install github.com/ast-metrics/ast-metrics/cmd/ast-metrics@latest

Verify Installation

Verify that the installation worked by opening a new terminal session and listing AST Metrics's available subcommands.

ast-metrics --help

You should see the help message with the available subcommands.

Troubleshooting

If you get an error that the command ast-metrics is not found, you may need to add the directory where the binary is located to your PATH.

Updating

Update is really easy. Just run:

ast-metrics self-update

If you installed AST Metrics with Homebrew, a package manager or Docker, update it the usual way instead (brew upgrade ast-metrics, docker pull, or the package of the new release).