To downgrade npm
to an older version, you need to use the npm install -g npm@<version>
command. Replace <version>
with the version of npm you want to install.
The npm
package is installed globally, so you need to add the -g
flag when you need to downgrade it.
For example, Supposey you have npm
version 8 installed. Here’s how to downgrade it to version 7:
$ npm -v
8.12.1
$ npm install -g npm@7
# wait for install to complete
$ npm -v
7.24.2
As you can see from the snippet above, the npm install
command will overwrite any existing package with the same name.
You can specify the full manor.minor.patch
version, or you can specify only the major
version as shown above (npm will use the latest minor
and patch
version when they are not defined)
To conclude, the npm
package you used to run npm commands is just another package installed globally when you install Node.js on your computer.
To downgrade it, you need to overwrite the installed version with the npm install -g npm@<version>
command.
Now you’ve learned how to downgrade the npm
package. Nice work! 👍