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

Better Stack Team
Updated on March 11, 2024

To install a specific version of an npm package, you can use the npm install command along with the package name and the desired version number. Here's the syntax:

 
npm install <package_name>@<version_number>

Replace <package_name> with the name of the package and <version_number> with the specific version you want to install.

For example, to install version 1.2.3 of a package named "example-package," you would run:

 
npm install example-package@1.2.3

Additionally, you can use other version specifiers, such as tilde (~) or caret (^), to specify version ranges. For example:

 
npm install example-package@^1.2.0

This would install the latest version compatible with version 1.2.0.

If you want to install a specific version globally, you can use the -g flag:

 
npm install -g example-package@1.2.3

Keep in mind that specifying exact versions may lead to potential issues in the long term, as you won't automatically receive updates. It's generally a good practice to use version ranges or semver specifiers when possible.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github