NewNode 26.14: mockResolvedValue and Friends in node:test →
w3/w3-tutorials

Install Rust CLI tools with pnpm 12.25, no rustup needed

pnpm 12.25 can build and run Rust crates like ripgrep and fd with a toolchain it manages itself. Run tools once with pnx, install them globally, and pin or upgrade them.

Updated Nov 30, 20267 min readBeginnerpnpm 12.25.1 · rust 1.100.1

Plenty of good command-line tools are written in Rust: ripgrep, fd, hyperfine and just, among others. Installing them usually means installing rustup first, then running cargo install. pnpm 12.25 adds a shortcut. pnx crate:<name> downloads a crate, builds it with a Rust toolchain pnpm manages itself, and runs it. pnpm add -g crate:<name> keeps it on your PATH.

In this guide you'll run ripgrep once without installing it, install it globally, pin and upgrade it, and remove it again. You don't need rustup or ~/.cargo at any point.

What you need

  • pnpm 12.25.0 or later. Check with pnpm --version. If you're on an older release, see the pnpm installation docs.
  • A C linker. Rust uses the system linker to produce the final binary. On macOS, run xcode-select --install if you don't have the Command Line Tools. On Linux, install GCC or Clang. The Rust book covers this.
terminal
pnpm --version
text
12.25.1

1. Run a tool once with pnx

pnx is pnpm's npx. With a crate: prefix it fetches the crate from crates.io instead of npm:

terminal
pnx crate:ripgrep --version

The first run does three things. It installs a stable Rust toolchain into the pnpm store, downloads ripgrep and its dependencies, and compiles a release build. Here is the output, with the progress lines and 38 Compiling lines removed:

text
Installing Rust 1.100.1 (aarch64-apple-darwin)
warning: [email protected]: output from `git rev-parse` is empty, so skipping embedding of commit hash
    Finished `release` profile [optimized + debuginfo] target(s) in 48.93s
ripgrep 16.0.0

features:-pcre2
simd(compile):+NEON
simd(runtime):+NEON

PCRE2 is not available in this build of ripgrep.
Done in 1m 0.2s using pnpm v12.25.1

That took a minute on an Apple silicon Mac. The compiled binary is kept in pnpm's dlx cache, so running the same command again takes about a second:

text
ripgrep 16.0.0

features:-pcre2
simd(compile):+NEON
simd(runtime):+NEON

PCRE2 is not available in this build of ripgrep.
Done in 1.3s using pnpm v12.25.1

pnpm builds with the crate's own Cargo.lock, the same as cargo install --locked. You get the dependency versions the authors tested, not whatever is newest today. The git rev-parse warning is harmless. It means the crate was built from a published archive, not a git checkout, so there's no commit hash to embed.

2. Pick the version and the executable

Versions follow the same rules as cargo install:

SpecifierRuns
crate:ripgrepThe newest stable release
crate:ripgrep@14The newest release that matches ^14
crate:[email protected]Exactly 14.1.1

The ripgrep crate's executable is called rg, not ripgrep. pnx runs the executable named after the crate, or the only one the crate has. When neither works, or you want to pass real arguments, name the crate with --package and the command after it:

terminal
pnx --package=crate:ripgrep@14 rg TODO src
text
src/index.ts:// TODO: add tests
src/math.ts:  // TODO: handle NaN
Done in 416ms using pnpm v12.25.1

fd is a good example of the "only executable" rule. The crate is fd-find and the binary is fd, but it's the crate's only executable, so this works without --package:

terminal
pnx crate:fd-find --version
text
warning: stripping debug info with `rust-objcopy` failed: signal: 6 (SIGABRT)
  |
  = note: dyld[65014]: Library not loaded: @rpath/libLLVM.dylib
...
    Finished `release` profile [optimized] target(s) in 1m 15s
fd 10.5.2
Done in 1m 20.2s using pnpm v12.25.1

3. Install it globally

For a tool you use every day, install it so it's always on your PATH:

terminal
pnpm add -g crate:ripgrep@14
text
Installed crate:ripgrep 14.1.1 globally
Done in 251ms using pnpm v12.25.1

That finished in a quarter of a second because the earlier pnx run had already built 14.1.1. Otherwise it compiles here, just like the first pnx run.

The executable goes into pnpm's global bin directory, $PNPM_HOME/bin. pnpm setup adds that directory to your shell's PATH if it isn't there yet:

terminal
rg --version | head -1
pnpm list -g
text
ripgrep 14.1.1
...
│   dependencies:
└── crate:[email protected]

pnpm lists the crate with its crate: prefix, next to any global npm packages. If the global bin directory already has a command with the same name from another package, pnpm stops with ERR_PNPM_GLOBAL_BIN_CONFLICT instead of overwriting it. The global packages docs describe the rule.

4. Update within a range, or jump to the latest

The version you add with is remembered. A plain update stays inside it:

terminal
pnpm update -g crate:ripgrep
text
crate:ripgrep is up to date at 14.1.1
Done in 262ms using pnpm v12.25.1

ripgrep 16.0.0 came out on 22 November 2026, but @14 keeps you on 14.x. That's useful when a major release changes flags your scripts rely on. Pass --latest to move to the newest stable release:

terminal
pnpm update -g crate:ripgrep --latest
text
warning: [email protected]: output from `git rev-parse` is empty, so skipping embedding of commit hash
    Finished `release` profile [optimized + debuginfo] target(s) in 51.39s
Updated crate:ripgrep from 14.1.1 to 16.0.0
Done in 55.3s using pnpm v12.25.1

rg --version now prints ripgrep 16.0.0. Note that pnpm outdated -g doesn't check crates yet, so it won't tell you when a new release is out.

5. Remove it

terminal
pnpm remove -g crate:ripgrep
text
Removed crate:ripgrep
Done in 5ms using pnpm v12.25.1

rg is gone from your PATH. The Rust toolchain stays in the store for the next crate.

Where the files go

Everything lives under pnpm's own directories:

  • The toolchain is in the store under rust/. It took about 450 MB on macOS.
  • Built executables are in the dlx cache until dlxCacheMaxAge expires, and global ones are linked into $PNPM_HOME/bin.
  • Nothing is written to ~/.rustup or ~/.cargo. If you already use rustup, the two don't interfere.

pnpm checks the toolchain download against the Rust release signing key. The Cargo page of the pnpm docs has the details.

Trade-offs and when not to use it

  • You run the crate's code at build time. Build scripts and procedural macros of the crate and every dependency run on your machine, exactly as with cargo install. Naming the crate is your consent, and --allow-build doesn't apply. If ignoreScripts is on, pnpm refuses to build crates at all.
  • Every install is a compile. Expect about a minute per tool, and longer on slow CI runners. If a project ships prebuilt binaries, cargo-binstall or your OS package manager is faster.
  • 450 MB for the toolchain. That's fine on a laptop and wasteful in a short-lived container that only needs one tool.
  • If you already use rustup, cargo install --locked ripgrep does the same job. The pnpm route is most useful on machines where you don't want a full Rust setup: JavaScript-only laptops, dev containers, or a team that already standardises on pnpm.
  • It's experimental. The pnpm docs mark multi-ecosystem support as experimental, so settings and layout may change.

Some Cargo tools, such as cargo-dylint, call rustup themselves to get a nightly toolchain. For those, pnpm can install a private rustup alongside the crate with pnpm add -g crate:cargo-dylint,rustup. See Running a crate with rustup.

Next steps

Related tutorials