Logo

How to install a previous exact version of a NPM package?

If you need to install a specific older version of an npm package—rather than the latest—append @<version> to the package name. For example, installing version 4.17.11 of lodash:

npm install lodash@4.17.11

Key Points:

  1. This command installs exactly 4.17.11 of lodash into your local node_modules folder.
  2. It also writes ^4.17.11 in your package.json by default, unless you specify --save-exact or manually edit package.json.
  3. To install it as a dev dependency (useful for build tools, testing frameworks, etc.), append --save-dev:
    npm install --save-dev lodash@4.17.11
  4. If you want to pin the version strictly (no caret ^ or tilde ~ in package.json), run:
    npm install --save-exact lodash@4.17.11
    This ensures that you always get the exact version specified, without minor or patch updates.

Finding Versions:

  • You can check available versions via the npm registry or using:
    npm info <package-name> versions
  • Look for the one you want and reference it with the @<version> syntax as shown above.

That’s it! You’ll now have that specific package version installed in your project.

Recommended Resource

CONTRIBUTOR
TechGrind