npm, Yarn, and pnpm Command Reference
npm, Yarn, and pnpm solve the same problem with different commands and, in pnpm's case, a genuinely different dependency storage model. This reference maps the everyday commands across all three side by side, since switching between projects that use different package managers is common and the small command differences are easy to mix up.
Key Takeaways
- The core actions — install everything, add a package, remove a package, run a script — exist in all three, just with slightly different flags and verbs
- pnpm uses a content-addressable store and hard links, which saves disk space across projects but is otherwise command-compatible with npm/Yarn for daily use
- Never mix lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml) in the same project — pick one package manager per project and commit only its lockfile
- A "clean install" command (npm ci, yarn install --frozen-lockfile, pnpm install --frozen-lockfile) is what CI pipelines should use, not the regular install command
- Global installs are for CLI tools you want available system-wide, not for project dependencies
Installing all dependencies
Running the plain install command reads package.json and the lockfile and installs everything into node_modules. This is the first command run after cloning a project or after pulling changes that touched package.json.
npm install
yarn install
pnpm installAdding a dependency
All three add a package and update both package.json and the lockfile. Use a "dev" flag to add it only as a development dependency (build tools, test frameworks) rather than a runtime dependency.
npm install axios # or: npm i axios
yarn add axios
pnpm add axios
# as a dev dependency:
npm install -D vitest
yarn add -D vitest
pnpm add -D vitestRemoving a dependency
All three remove the package from node_modules and update package.json and the lockfile in one step.
npm uninstall axios
yarn remove axios
pnpm remove axiosRunning package.json scripts
Scripts defined under "scripts" in package.json (like "build" or "test") are run the same way across all three, with npm requiring "run" for custom script names (though npm start and npm test work without "run" as special cases).
npm run build
yarn build
pnpm buildClean installs for CI
CI pipelines should use the strict, lockfile-respecting install variant, which fails if package.json and the lockfile are out of sync, rather than silently updating the lockfile. This is what actually catches "works on my machine" dependency drift before it reaches production.
npm ci
yarn install --frozen-lockfile
pnpm install --frozen-lockfileGlobal installs
A global install makes a CLI tool available system-wide from any directory, separate from any single project's dependencies — use this only for tools you invoke directly from a terminal (like a scaffolding CLI), not for anything a project's code actually imports.
npm install -g typescript
yarn global add typescript
pnpm add -g typescriptCommon Mistakes to Avoid
- ✗Having more than one lockfile (package-lock.json and yarn.lock together) in the same project, which causes inconsistent installs between team members
- ✗Using the regular install command in CI instead of the frozen-lockfile variant, letting a mismatched lockfile silently update instead of failing the build
- ✗Installing a build-time-only tool (like a test framework) as a regular dependency instead of a dev dependency
- ✗Assuming a package manager switch (e.g., npm to pnpm) requires no changes — the lockfile format is different and old lockfiles from another tool should be deleted, not kept alongside the new one
- ✗Global-installing a package that a project actually depends on in code, instead of adding it as a proper project dependency
Frequently Asked Questions
Can I use npm, Yarn, and pnpm interchangeably on the same project?▾
Not safely at the same time — pick one per project and commit only its lockfile. Mixing lockfiles or switching tools without removing the old lockfile and node_modules can produce inconsistent dependency resolution between team members and CI.
What's the difference between npm install and npm ci?▾
npm install will update the lockfile if package.json and the lockfile disagree, and can install slightly different versions across environments over time. npm ci requires the lockfile and package.json to already agree, installs exactly what's locked, and fails loudly if they don't match — which is why it's the correct choice for CI.
Why does pnpm save disk space compared to npm and Yarn?▾
pnpm stores package files once in a global content-addressable store and uses hard links (and a symlinked node_modules structure) across projects, instead of copying full copies of every package into every project's node_modules — the day-to-day commands otherwise work the same way as npm/Yarn.
Related Tools
Related Guides
Git Command Reference for Developers
The Git commands developers actually use day to day — status, branching, staging, committing, and safely undoing changes — with the distinctions that matter (like reset vs revert).
Docker Command Reference for Developers
The Docker commands used for everyday container work — running, inspecting, logging, and cleaning up containers and images — without needing the full Docker CLI manual.
Last reviewed: 2026 · Written and verified by the Dev Utilities team · Editorial policy
Report an issue with this guide →