Use npm ci in CI and deployments and npm install on your own machine. npm ci installs exactly what package-lock.json records and stops with an error if package.json disagrees with it. npm install reconciles the two and may rewrite the lockfile. In our test with npm 10.9.9, a lockfile pinned to semver 7.5.0 stayed at 7.5.0 under both commands until we raised the range in package.json; then npm ci failed and npm install moved the lock to 7.8.6.
The differences in one table
The npm documentation for npm ci lists the rules. We checked each against a real project on npm 10.9.9 (Node 22.23.4), and the documentation page for npm 11 on 27 November 2026.
npm install | npm ci | |
|---|---|---|
| Needs a lockfile | No. It creates package-lock.json if missing. | Yes. package-lock.json or npm-shrinkwrap.json must exist. |
Lockfile and package.json disagree | Updates the lockfile to satisfy package.json. | Exits with an error and changes nothing. |
Writes package.json or the lockfile | Can write both. | Never. The docs call installs “essentially frozen”. |
Existing node_modules | Reused and adjusted. | Removed first, then a clean install. |
| Add one package | Yes: npm install <name>. | No. It installs the entire project only. |
| Intended for | Day-to-day development. | “Automated environments such as test platforms, continuous integration, and deployment”. |
What happens when they disagree: a test
We made a project with one dependency, semver, and generated a lockfile without installing anything (npm install --package-lock-only). Then we changed only the range in package.json and ran each command.
| Step | package.json range | Lockfile has | Command | Result |
|---|---|---|---|---|
| 1 | 7.5.0 (exact) | 7.5.0 | npm install --package-lock-only | Lockfile written with semver 7.5.0 |
| 2 | ^7.5.0 | 7.5.0 | npm ci --dry-run | Would add 3 packages: semver 7.5.0, yallist 4.0.0, lru-cache 6.0.0 |
| 3 | ^7.5.0 | 7.5.0 | npm install --package-lock-only | “up to date”; lock still 7.5.0 |
| 4 | ^7.6.0 | 7.5.0 | npm ci --dry-run | Error code EUSAGE |
| 5 | ^7.6.0 | 7.5.0 | npm install --package-lock-only | Lock rewritten to semver 7.8.6 |
Two things stand out. In steps 2 and 3 the range ^7.5.0 allows newer versions (the registry’s latest was 7.8.6 when we tested), yet both commands kept 7.5.0. A lockfile that still satisfies the range wins over “newest in range”; neither command goes looking for updates on its own. The caret rules themselves are covered in our guide to semantic versioning.
In step 4 the lockfile no longer satisfied the new range, and npm ci refused to continue. The message, as printed:
npm error code EUSAGE
npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lockfile with `npm install` before continuing.
npm error Invalid: lock file's semver@7.5.0 does not satisfy semver@7.8.6
That error is the reason to use npm ci in a pipeline. If a teammate edits package.json and forgets to commit the updated lockfile, the build fails at once instead of quietly installing something nobody reviewed. Step 5 shows the other side: npm install fixed the disagreement by moving the lock to 7.8.6, the newest version allowed by ^7.6.0, and that rewrite lands in your working tree for you to commit.
Which one to run, and when
- Your laptop, adding or upgrading a dependency:
npm install <name>, then commit bothpackage.jsonandpackage-lock.json. - CI, test jobs, container builds, deploys:
npm ci. The build then uses the versions you committed, and a mismatch is a failed build. - A fresh clone you only want to run: either works if the lockfile is in sync;
npm ciis the stricter choice and clears any stalenode_modules. - You want to know what would change before you run it: add
--dry-run, as in our test. The option is listed for both commands in the docs.
Mistakes that make npm ci fail
- Lockfile not committed.
npm cihas nothing to install from. Commitpackage-lock.json. package.jsonedited by hand. Runnpm installlocally, then commit the changed lockfile.- Different flags when the lockfile was made. The npm docs warn that if you created the lockfile with flags that change the tree shape, such as
--legacy-peer-depsor--install-links, you must pass the same flags tonpm ci. Their suggestion is to set the flag in a project.npmrcand commit that file. - Expecting
npm cito fix things. It will never repair or refresh a lockfile. That is the point.
A lockfile fixes versions, not trust. It does not tell you whether a pinned package is safe; for that, see how a software dependency becomes a security risk and how reproducible builds check a download against its source.





