npm ci vs npm install: when to use which - Rocketeers

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com) 

 On this page

 Knowledge
---------

npm ci vs npm install: when to use which
========================================

### [\#Development](https://rocketee.rs/index.php/development)

npm install resolves dependencies and updates your lockfile as it goes. npm ci does a clean, exact install straight from the lockfile, which is what you want in CI and production builds.

 Published by [Mark van Eijk](https://rocketee.rs/index.php/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [What npm install does](#content-what-npm-install-does)
2. [What npm ci does](#content-what-npm-ci-does)
3. [The catch: the lockfile must exist and match](#content-the-catch-the-lockfile-must-exist-and-match)
4. [When to use which](#content-when-to-use-which)

[\#](#content-what-npm-install-does "Permalink")What npm install does
---------------------------------------------------------------------

`npm install` is the everyday command for adding and updating dependencies:

 ```
npm install
npm install lodash       # add a package

```

It reads `package.json`, resolves versions, installs them, and **writes** the result to `package-lock.json`. If a dependency allows a newer version within its range, the lockfile can change. That flexibility is exactly what you want while developing.

[\#](#content-what-npm-ci-does "Permalink")What npm ci does
-----------------------------------------------------------

`npm ci` (clean install) is built for automated and reproducible installs:

 ```
npm ci

```

It behaves differently in three important ways:

- It installs **exactly** what is in `package-lock.json`, ignoring version ranges in `package.json`.
- It **deletes** `node_modules` first, so you always start from a clean slate.
- It **never writes** to `package.json` or `package-lock.json`.

It is also typically faster than `npm install` because it skips dependency resolution.

[\#](#content-the-catch-the-lockfile-must-exist-and-match "Permalink")The catch: the lockfile must exist and match
------------------------------------------------------------------------------------------------------------------

`npm ci` requires a `package-lock.json` (or `npm-shrinkwrap.json`), and that lockfile must be in sync with `package.json`. If they disagree, it fails on purpose rather than silently "fixing" things:

 ```
npm ci can only install packages when your package.json and
package-lock.json are in sync. ...

```

The fix is to run `npm install` locally, commit the updated lockfile, and try again.

[\#](#content-when-to-use-which "Permalink")When to use which
-------------------------------------------------------------

 Situation Use  Day-to-day development `npm install` Adding or upgrading a package `npm install ` CI / CD pipelines `npm ci` Production / Docker builds `npm ci`The rule of thumb: if you want reproducible, lockfile-exact installs, use `npm ci`. If you intend to change your dependencies, use `npm install`. Because `npm ci` wipes `node_modules`, it also clears up the kind of half-installed state that otherwise has people deleting the folder by hand.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Development](https://rocketee.rs/index.php/development)

- [Install PHP memcached extension on macOS](https://rocketee.rs/index.php/install-php-memcached-extension-on-macos)
- [How to delete a local (and remote) Git branch](https://rocketee.rs/index.php/git-delete-local-branch)
- [Fix: Cannot connect to the Docker daemon at unix:///var/run/docker.sock](https://rocketee.rs/index.php/cannot-connect-to-docker-daemon)
- [git stash pop vs apply: save and restore changes](https://rocketee.rs/index.php/git-stash-pop)
- [How to clean up Docker with prune (images, volumes, system)](https://rocketee.rs/index.php/docker-prune)
- [What port does SSH use (and how to change it)](https://rocketee.rs/index.php/ssh-port)

 [View all 12 articles →](https://rocketee.rs/index.php/development)
