install npm package specific version

How to Install Specific Version of NPM Package

NPM is the package manager for NodeJS framework and allows you to install, upgrade and manage various packages for your NodeJS applications. By default, it fetches the latest version of any package, for installation. Sometimes you may need to install exact version of NPM package or older version of NPM package. This is generally required if you are facing compatibility issues with other packages. In this article, we will look at how you can easily install specific version of NPM package.


How to Install Specific Version of NPM Package

You can easily install specific NPM packages using @ notation while using NPM command. Here is the syntax to install exact version of NPM package.

$ npm install <package>@<version>

In the above command you need to mention package name in place of <package> and version in place of <version>.

For example if you want to install expressjs version 1.1.1 then run the following command.

$ npm install express@1.1.1

You can also run the above command for global packages using -g option.

$ npm install -g express@1.1.1

If you want to view all available versions for a given NPM package just run the following command

npm view <package> versions

Here is an example to list all available versions of cowsay package.

❯ npm view cowsay versions
[ '1.0.0',
  '1.0.1',
  '1.0.2',
  '1.0.3',
  '1.1.0',
  '1.1.1',
  '1.1.2',
  '1.1.3',
  '1.1.4',
  '1.1.5',
  '1.1.6',
  '1.1.7',
  '1.1.8',
  '1.1.9',
  '1.2.0',
  '1.2.1',
  '1.3.0',
  '1.3.1' ]

It is advisable to check out the available versions of a given package before you install it, to avoid errors.

That’s it. As you can see it is very easy to install exact version of NPM package. If you don’t specify any version then npm install command will automatically install the latest version.

Installing the exact version of NPM package becomes necessary if some of your npm packages face compatibility issues.

If you want to find out which packages have been installed on your system, along with their versions, just run npm list command and it will display a list of all npm packages on your system.

$ sudo npm list

Also read:

How to Disable TLS 1.0 in Apache Server
How to Force User to Change Password on Login
Shell Script to Automate SSH Login
How to Pause Shell Script in Linux
How to Send HTML Mail Using Python

Leave a Reply

Your email address will not be published.