Skip to main content

pnpm Cheatsheet

By Dejan Panovski Updated on Download PDF

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.

CommandDescription
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-pnpmInstall through npm
pnpm self-updateUpdate pnpm to the current release
pnpm self-update 12.3.4Move to a specific pnpm version
pnpm setupCreate PNPM_HOME and update the shell profile
pnpm --versionPrint the installed pnpm version

Node.js Runtimes

Install language runtimes with pnpm itself.

CommandDescription
pnpm runtime set node lts -gInstall the Node.js LTS release
pnpm runtime set node 22 -gInstall a Node.js major version
pnpm runtime set node latest -gInstall the newest Node.js release
pnpm runtime set node 22.23.2 -gInstall an exact Node.js version
pnpm runtime set deno 2 -gInstall Deno
pnpm runtime set bun latest -gInstall Bun

Project Setup

Create and edit project metadata.

CommandDescription
pnpm initCreate package.json
pnpm init --init-package-managerCreate package.json and pin pnpm
pnpm init --bareCreate package.json with required fields only
pnpm importBuild pnpm-lock.yaml from another lockfile
pnpm pkg get namePrint a package.json field
pnpm pkg set scripts.start="node index.js"Add or update a field
pnpm pkg delete scripts.oldRemove a package.json field

Add Dependencies

Record packages in package.json and the lockfile.

CommandDescription
pnpm add expressAdd a runtime dependency
pnpm add -D eslintAdd a development dependency
pnpm add -O sharpAdd an optional dependency
pnpm add -E expressAdd without a version range
pnpm add express@5.1.0Add a specific version
pnpm add -g http-serverAdd a global package
pnpm add -w typescriptAdd to the workspace root

Install Dependencies

Reproduce a dependency tree from the lockfile.

CommandDescription
pnpm installInstall everything package.json declares
pnpm install --frozen-lockfileInstall without changing the lockfile
pnpm ciClean install for CI pipelines
pnpm install --prodSkip development dependencies
pnpm install --offlineInstall from the store only
pnpm install --ignore-scriptsInstall without lifecycle scripts
pnpm fetchFetch the lockfile contents into the store

Update and Inspect

Check versions and trace where packages come from.

CommandDescription
pnpm outdatedShow packages with newer versions
pnpm updateUpdate within package.json ranges
pnpm update express --latestUpdate one package and its range
pnpm update -iChoose updates interactively
pnpm list --depth 0List direct dependencies
pnpm why expressExplain why a package is installed
pnpm licenses listList dependency licenses

Remove and Clean

Drop packages and reclaim project space.

CommandDescription
pnpm remove expressRemove a dependency
pnpm remove -g http-serverRemove a global package
pnpm pruneRemove extraneous packages
pnpm prune --prodRemove development dependencies
pnpm dedupeCollapse duplicate versions in the lockfile
pnpm dedupe --checkReport duplicates without writing
pnpm pm cleanRemove node_modules from every workspace project

Scripts and Execution

Run package scripts and one-off tools.

CommandDescription
pnpm run buildRun a named script
pnpm startRun the start script
pnpm testRun the test script
pnpm run build -- --watchPass arguments to a script
pnpm exec eslint .Run a local package binary
pnpm dlx create-vite@latest appRun 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.

CommandDescription
pnpm -r run buildRun a script in every workspace package
pnpm --filter web-app add zodAdd a dependency to one package
pnpm --filter web-app run testRun a script in one package
pnpm --filter "@scope/*" testSelect packages by pattern
pnpm --filter web-app... buildSelect a package and its dependencies
pnpm --filter ...web-app buildSelect a package and its dependents
pnpm --filter "...[origin/main]" buildSelect packages changed since a branch

Store and Cache

Maintain the shared content-addressable store.

CommandDescription
pnpm store pathPrint the store location
pnpm store statusCheck the store for modified packages
pnpm store pruneRemove orphaned packages from the store
pnpm store add express@5.1.0Add a package to the store
pnpm cache pathPrint the metadata cache directory
pnpm root -gPrint the global node_modules path
pnpm bin -gPrint the global binary directory

Security and Diagnostics

Audit dependencies and check the installation.

CommandDescription
pnpm auditScan dependencies for advisories
pnpm audit --prodAudit production dependencies only
pnpm audit --fixAdd overrides for non-vulnerable versions
pnpm doctorRun diagnostics on the pnpm environment
pnpm sbom --sbom-format spdxGenerate a software bill of materials
pnpm approve-buildsApprove dependency build scripts
pnpm ignored-buildsList packages with blocked build scripts

Use these references for Node.js package workflows.

GuideDescription
pnpm CommandFull pnpm tutorial with examples
npm CommandThe npm equivalents of these commands
Install Node.js on Ubuntu 26.04Install Node.js and npm