How to Install an Older Version of an npm Package
If you encounter a compatibility problem or need to use a specific version of an npm package, you might want to install an older version. Fortunately, the process is straightforward.
To install an old version of an npm package, you can use the @
syntax. Here’s an example of the command:
npm install <package>@<version>
Let’s say you want to install cowsay
, and you want to use version 1.3.1 (at the time of writing). You can use the following command:
npm install [email protected]
If you need to install version 1.2.0 instead, you can modify the command like this:
npm install [email protected]
The same syntax is applicable for global packages as well. To install a specific version globally, you can use the -g
flag:
npm install -g [email protected]
Additionally, if you want to check all the previous versions of a package, you can use the npm view
command with the keyword versions
. For example:
❯ 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' ]
By following these steps, you can easily install an older version of an npm package and resolve any compatibility issues you may encounter.