As you might already know, there are a large number of npm packages released every day. An equally large number of updates too get released on the npm registry. While we would like to keep the dependencies in package.json updated to the latest version most of the times, there are still times when we would like to install specific version of npm package for certain reasons.
How to install an exact or specific version of npm package?
In order to install a specific version of npm package run the npm install command along with the package name followed by the version number prefixed with the at symbol “@”. Here is the syntax for the same:
npm install <package_name>@version_number
For example, let’s say I wanted to install React version 17.0.2, then the command would be :
npm install react@17.0.2
If you notice, the command is very similar to the basic command to install a package, however, the only difference is the @version_number that follows the package name as a suffix.
How to install the latest version of a package in npm?
On the other hand, if you would like to install the latest version of an npm package , use the same command but instead of specifying the version number, use the “latest” keyword like:
npm install <package_name>@latest
For example, to install the latest version of React, the command would be
npm install react@latest
Please note that both these commands can be used along with the --save
and --save-dev
etc flags too whenever required.
As you can see, it is quite simple to install specific version of npm package or to install the latest version of a package too. You can also find outdated packages or unused dependencies in npm and remove those npm packages too in order to keep your project optimized. Hope you found this article helpful.
The post How to install specific version of npm package? first appeared on MoreOnFew.
Top comments (0)