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:
1 | 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:
1 | npm install [email protected] |
If you need to install version 1.2.0 instead, you can modify the command like this:
1 | 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:
1 | 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:
1 | ❯ npm view cowsay versions |
By following these steps, you can easily install an older version of an npm package and resolve any compatibility issues you may encounter.
tags: [“npm”, “package management”, “compatibility”, “command line”, “version control”]