NPM (Node Package Manager) is the default package manager of NodeJS framework. It allows you to easily install & manager NodeJS packages. When we install a NodeJS package using NPM, by default, it installs the latest package. But sometimes you may need to install a specific version of NPM package for NodeJS. This is typically required in case of compatibility issues. In this article, we will learn how to install specific version of NPM package.
How to Install Specific Version of NPM Package
Here is the typical syntax of NPM command.
$ npm install package
The above command will download & install the default package version. But if you want to download a specific version of the package you need to specify the version number using @ notation as shown below.
$ npm install package@version
For example, here is the command to install express package version 1.1.1.
$ npm install express@1.1.1
If you want to do a global installation, you can use also use -g option as shown.
$ npm install -g express@1.1.1
Please note, if you do not specify the right version, then the npm command will give an error. So you can use ‘npm view’ command to list all available versions of a given package.
$ npm view package versions
Here is a list of all available versions for expressjs.
$ npms view express 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 always better to get a list of supported package versions before installing a specific package version.
In this article, we have learnt how to easily install a specific version of NPM package. If you don’t mention the package version, then NPM will install the latest version. If you want to know the packages installed on your system, along with their package versions, use the following command.
$ sudo npm list
Also read:
How to Disable GZIP Compression in Linux
How to Disable TLS 1.0 in Apache
Shell Script to Automate SSH Login
How to Force User to Change Password in Linux
How to Pause Shell Script
Related posts:
Sreeram Sreenivasan loves coding & writing tech articles. He has helped many Fortune 500 companies in the areas of BI & software development. He has more than 10 years of experience in web development, Python, Linux, SQL and database programming.