DEV Community

MoreOnFew
MoreOnFew

Posted on • Originally published at moreonfew.com on

How to install specific version of npm package?

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

For example, to install the latest version of React, the command would be

npm install react@latest
Enter fullscreen mode Exit fullscreen mode

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay