# Install cargo-expand with Homebrew, apk, Nix, pacman

Show what Rust code looks like with macros expanded. Version 1.0.124 via Homebrew; verified 2026-07-19. Also installable with nix: nix profile install nixpkgs#cargo-expand.

## Install

```sh
sudo av install brew:cargo-expand
```

Additional install commands:

### macOS

- Homebrew (100%):

```sh
brew install cargo-expand
```

  Evidence: local Homebrew formula metadata

### Linux

- apk (92%):

```sh
sudo apk add cargo-expand
```

  Evidence: Alpine Linux edge package indexes: cargo-expand from https://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz

- Nix (92%):

```sh
nix profile install nixpkgs#cargo-expand
```

  Evidence: nixpkgs package indexes: pkgs/by-name/ca/cargo-expand/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1

- pacman (92%):

```sh
sudo pacman -S cargo-expand
```

  Evidence: Arch Linux sync databases: cargo-expand from https://geo.mirror.pkgbuild.com/extra/os/x86_64/extra.db.tar.gz

## Package facts

- **Package key:** brew:cargo-expand
- **Package manager:** Homebrew
- **Version:** 1.0.124
- **Source summary:** Show what Rust code looks like with macros expanded
- **Homepage:** <https://github.com/dtolnay/cargo-expand>
- **Repository:** <https://github.com/dtolnay/cargo-expand>
- **Last updated:** 2026-07-19T01:08:28Z
- **Generated:** 2026-08-03T19:37:03+00:00

## Executables

- cargo-expand (alias)

## Install behavior

- Bottle: not available

## Freshness

- Page generated: 2026-08-03
- Package-manager version: 1.0.124
## Project history and usage

cargo-expand is the standard Rust developer tool for seeing macro-expanded code from a Cargo project. It wraps compiler expansion output in an ergonomic Cargo subcommand and formats the result for human inspection.

### Project history

The GitHub repository and crates.io crate were both created in June 2016. The README describes cargo-expand as a wrapper around `cargo rustc --profile=check -- -Zunpretty=expanded`, printing the result of macro expansion and derive expansion for the current crate.

The project was created by David Tolnay, whose broader Rust tooling ecosystem includes heavily used macro and parsing crates. cargo-expand became especially useful as Rust derive macros, procedural macros, and macro-heavy libraries became common in everyday Rust code.

The README includes an explicit disclaimer that macro expansion to text is lossy and intended as a debugging aid, not a promise that the printed code can be compiled or behaves exactly like the original.

### Adoption history

cargo-expand is widely adopted: it is packaged by Homebrew, Nix, Arch Linux, and Alpine in the supplied facts, and crates.io records millions of downloads. Its GitHub repository also has thousands of stars, strong evidence that it is a mainstream Rust diagnostic tool.

Its adoption tracks the rise of procedural macros and derive-heavy frameworks in Rust. When generated code is hard to reason about, `cargo expand` became the common first tool for understanding what the compiler is seeing.

### How it is used

Users run `cargo expand` in a Cargo project to print expanded code. Common variants include expanding a test target, selecting a module or item path, disabling rustfmt with `--ugly`, or using configuration under the `[expand]` section of `$CARGO_HOME/config.toml`.

cargo-expand optionally formats output with rustfmt and can use themes or paging configured in Cargo's user config file, making compiler-oriented output easier to read in terminals.

### Why package nerds care

cargo-expand matters because macro expansion is one of Rust packaging's hidden dependency surfaces: derives and procedural macros can add trait impls, bounds, helper items, and code paths that are invisible in source form. Seeing that generated code helps maintainers debug builds, features, and public API behavior.

It is also a classic Cargo-subcommand success story: a thin, focused wrapper around a compiler capability became the community default because it matched how Rust developers actually inspect package code.

### Timeline

- 2016: dtolnay/cargo-expand GitHub repository created.
- 2016: cargo-expand crate first published on crates.io.
- 2026: crates.io metadata shows active releases in the 1.0.x line.

### Related projects

- rustc provides the underlying macro expansion output exposed by cargo-expand.
- rustfmt is used to make expanded output more readable when installed.
- syn is referenced in README screenshots and is part of the wider Rust procedural macro tooling ecosystem.

### Sources

- <https://api.github.com/repos/dtolnay/cargo-expand>
- <https://crates.io/api/v1/crates/cargo-expand>
- <https://github.com/dtolnay/cargo-expand#readme>
- <https://raw.githubusercontent.com/dtolnay/cargo-expand/master/README.md>
- input.source_facts.package-manager


## Security Notes

No matching local secret-handling manifest was found for cargo-expand. Nucleus package metadata is still published here so future coverage has a stable package URL.



## Configuration and credential file locations

These source-backed paths show where this package keeps local settings or durable credentials. Automic Vault can use them as review targets for secret scanning, migration, and command approval.


## Configuration files

- Unix: $CARGO_HOME/config.toml, ~/.cargo/config.toml
## Other Package-Manager Records

- Nix - cargo-expand: normalized package name match | nixpkgs package indexes: pkgs/by-name/ca/cargo-expand/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1
- apk - cargo-expand - 1.0.122-r0: normalized package name match | Alpine Linux edge package indexes: cargo-expand from https://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz | Cargo subcommand to show result of macro expansion | https://github.com/dtolnay/cargo-expand
- apk - cargo-expand-doc - 1.0.122-r0: normalized package name match | Alpine Linux edge package indexes: cargo-expand-doc from https://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz | Cargo subcommand to show result of macro expansion (documentation) | https://github.com/dtolnay/cargo-expand
- pacman - cargo-expand - 1.0.124-1: normalized package name match | Arch Linux sync databases: cargo-expand from https://geo.mirror.pkgbuild.com/extra/os/x86_64/extra.db.tar.gz | Subcommand to show result of macro expansion | https://github.com/dtolnay/cargo-expand


## Combined YAML source

View the package source record on GitHub. [combined/cargo-expand.yml](https://github.com/mxcl/pkgdb/blob/main/combined/cargo-expand.yml)


## Sources

- pkg.so package database
- Geiger risk classifier
- curated configuration and credential file locations
- curated package history
- pkgdb category and tag curation
- external package-manager database matches
- cross-ecosystem install command graph
