pnpm Cheatsheet
Quick reference for pnpm commands covering installation, dependencies, lockfiles, scripts, workspace filtering, the package store, and Node.js runtimes
pnpm is a Node.js package manager that keeps package files in a shared content-addressable store and links them into each project. This cheatsheet covers installing pnpm and Node.js runtimes, adding and updating dependencies, running scripts, working across a monorepo with filters, and maintaining the store.
Install and Update pnpm
Set up the pnpm executable and keep it current.
| Command | Description |
|---|---|
curl -fsSL https://get.pnpm.io/install.sh | sh - | Install with the standalone script |
wget -qO- https://get.pnpm.io/install.sh | sh - | Install without curl |
npx get-pnpm | Install through npm |
pnpm self-update | Update pnpm to the current release |
pnpm self-update 12.3.4 | Move to a specific pnpm version |
pnpm setup | Create PNPM_HOME and update the shell profile |
pnpm --version | Print the installed pnpm version |
Node.js Runtimes
Install language runtimes with pnpm itself.
| Command | Description |
|---|---|
pnpm runtime set node lts -g | Install the Node.js LTS release |
pnpm runtime set node 22 -g | Install a Node.js major version |
pnpm runtime set node latest -g | Install the newest Node.js release |
pnpm runtime set node 22.23.2 -g | Install an exact Node.js version |
pnpm runtime set deno 2 -g | Install Deno |
pnpm runtime set bun latest -g | Install Bun |
Project Setup
Create and edit project metadata.
| Command | Description |
|---|---|
pnpm init | Create package.json |
pnpm init --init-package-manager | Create package.json and pin pnpm |
pnpm init --bare | Create package.json with required fields only |
pnpm import | Build pnpm-lock.yaml from another lockfile |
pnpm pkg get name | Print a package.json field |
pnpm pkg set scripts.start="node index.js" | Add or update a field |
pnpm pkg delete scripts.old | Remove a package.json field |
Add Dependencies
Record packages in package.json and the lockfile.
| Command | Description |
|---|---|
pnpm add express | Add a runtime dependency |
pnpm add -D eslint | Add a development dependency |
pnpm add -O sharp | Add an optional dependency |
pnpm add -E express | Add without a version range |
pnpm add express@5.1.0 | Add a specific version |
pnpm add -g http-server | Add a global package |
pnpm add -w typescript | Add to the workspace root |
Install Dependencies
Reproduce a dependency tree from the lockfile.
| Command | Description |
|---|---|
pnpm install | Install everything package.json declares |
pnpm install --frozen-lockfile | Install without changing the lockfile |
pnpm ci | Clean install for CI pipelines |
pnpm install --prod | Skip development dependencies |
pnpm install --offline | Install from the store only |
pnpm install --ignore-scripts | Install without lifecycle scripts |
pnpm fetch | Fetch the lockfile contents into the store |
Update and Inspect
Check versions and trace where packages come from.
| Command | Description |
|---|---|
pnpm outdated | Show packages with newer versions |
pnpm update | Update within package.json ranges |
pnpm update express --latest | Update one package and its range |
pnpm update -i | Choose updates interactively |
pnpm list --depth 0 | List direct dependencies |
pnpm why express | Explain why a package is installed |
pnpm licenses list | List dependency licenses |
Remove and Clean
Drop packages and reclaim project space.
| Command | Description |
|---|---|
pnpm remove express | Remove a dependency |
pnpm remove -g http-server | Remove a global package |
pnpm prune | Remove extraneous packages |
pnpm prune --prod | Remove development dependencies |
pnpm dedupe | Collapse duplicate versions in the lockfile |
pnpm dedupe --check | Report duplicates without writing |
pnpm pm clean | Remove node_modules from every workspace project |
Scripts and Execution
Run package scripts and one-off tools.
| Command | Description |
|---|---|
pnpm run build | Run a named script |
pnpm start | Run the start script |
pnpm test | Run the test script |
pnpm run build -- --watch | Pass arguments to a script |
pnpm exec eslint . | Run a local package binary |
pnpm dlx create-vite@latest app | Run a package without installing it |
pnpm pm <command> | Force a built-in command over a same-named script |
Workspaces and Filtering
Target one package or a slice of a monorepo.
| Command | Description |
|---|---|
pnpm -r run build | Run a script in every workspace package |
pnpm --filter web-app add zod | Add a dependency to one package |
pnpm --filter web-app run test | Run a script in one package |
pnpm --filter "@scope/*" test | Select packages by pattern |
pnpm --filter web-app... build | Select a package and its dependencies |
pnpm --filter ...web-app build | Select a package and its dependents |
pnpm --filter "...[origin/main]" build | Select packages changed since a branch |
Store and Cache
Maintain the shared content-addressable store.
| Command | Description |
|---|---|
pnpm store path | Print the store location |
pnpm store status | Check the store for modified packages |
pnpm store prune | Remove orphaned packages from the store |
pnpm store add express@5.1.0 | Add a package to the store |
pnpm cache path | Print the metadata cache directory |
pnpm root -g | Print the global node_modules path |
pnpm bin -g | Print the global binary directory |
Security and Diagnostics
Audit dependencies and check the installation.
| Command | Description |
|---|---|
pnpm audit | Scan dependencies for advisories |
pnpm audit --prod | Audit production dependencies only |
pnpm audit --fix | Add overrides for non-vulnerable versions |
pnpm doctor | Run diagnostics on the pnpm environment |
pnpm sbom --sbom-format spdx | Generate a software bill of materials |
pnpm approve-builds | Approve dependency build scripts |
pnpm ignored-builds | List packages with blocked build scripts |
Related Guides
Use these references for Node.js package workflows.
| Guide | Description |
|---|---|
pnpm Command | Full pnpm tutorial with examples |
npm Command | The npm equivalents of these commands |
Install Node.js on Ubuntu 26.04 | Install Node.js and npm |