Downgrade npm to an older version
Asked Answered
C

6

344

I tried updating npm to see if it would solve some dependency problems we were having, and now I want to downgrade to the version the rest of the development team is using. How can I install an older version?

I updated npm according to the instructions on the About npm CLI versions:

The latest release of npm

The latest release of npm is the most recent stable version. When you install Node.js, npm is automatically installed. However, npm is released more frequently than Node.js, so to install the latest stable version of npm, on the command line, run:

npm install npm@latest -g

Crow answered 25/9, 2017 at 22:54 Comment(1)
I suggest that you downgrade or update the node version, then the npm version should follow. You can do something like this : nvm use v16.16.0 it would then show version 8.11.0 for the npm and version 16.16.0 for the nodeSuffragette
C
551

Just replace @latest with the version number you want to downgrade to. I wanted to downgrade to version 3.10.10, so I used this command:

npm install -g [email protected]

If you're not sure which version you should use, look at the version history. For example, you can see that 3.10.10 is the latest version of npm 3.

Crow answered 25/9, 2017 at 22:54 Comment(10)
What does -g mean in this case? Can you have a repo-specific version of npm?Arenaceous
You can install npm in your repo, @JimAho, but you get a warning, and I couldn't figure out how to run the local version. Seems best to avoid this situation, I guess.Crow
g stands for globalPantechnicon
FYI: Make sure you do this from a cmd that has admin priv.Alice
Any idea on how to downgrade npm when a non-compatible Node version is installed? For example, Node is v8 and npm v7. It looks like Node 8 doesn't work fine with npm, so npm complaints about it and it doesn't let you downgrade to the compatible npm v6.Eating
For some Angular packages, I needed to downgrade npm to ^7.5.6. npm install -g npm@7 did the trick. Thanks!Classless
but npm -v still prints the latest versionSubedit
If you do get an error, you may want to sanity check your directory ownership by running the same command, but with sudoSunbathe
I get an error of: ENOTEMPTY: directory not empty, rename '~/.asdf/installs/nodejs/16.13.2/.npm/lib/node_modules/npm' -> '~/.asdf/installs/nodejs/16.13.2/.npm/lib/node_modules/.npm-75DsjTB1' maybe because I'm using asdf version manager? But then if I get rid of my npm directory how will npm be able to install npm 🤔? Might try rolling back my node version and hoping that works 🤷Stoneblind
It is not working... stillActinomycosis
A
68

Just need to add version of which you want

upgrade or downgrade

npm install -g npm@version

Example if you want to downgrade from npm 5.6.0 to 4.6.1 then,

npm install -g [email protected]

It is tested on linux

Anatropous answered 3/1, 2018 at 6:42 Comment(0)
L
33
npm install -g npm@4

This will install the latest version on the major release 4, so no need to specify version number. Replace 4 with whatever major release you want.

Laterality answered 21/3, 2018 at 10:24 Comment(0)
T
6

Even I run npm install -g npm@4, it is not ok for me.

Finally, I download and install the old node.js version.

https://nodejs.org/download/release/v7.10.1/

It is npm version 4.

You can choose any version here https://nodejs.org/download/release/

Trappist answered 28/3, 2018 at 6:45 Comment(4)
You can find the node.js with a specific version of npm by searching in Looking for latest release of a version branch?.Apolitical
This is the correct answer, npm is tied to the node versionSquarely
Soooo...you download the older version then you delete the newer? what are the next steps to actually running the app?Dialect
Doesn't work for me. I get the same error as when trying to use npm to install the older version: ERROR: npm v9.1.1 is known not to run...Kerley
C
1

For windows, you need to delete npm* folder in C:\Users\*\AppData\Roaming\npm* . Uninstall node js and reinstall them again with its compatible npm version.

Chintzy answered 18/10, 2023 at 8:7 Comment(0)
S
0

NVM (Node Version Manager) is also an option. Installation is here.

We can downgrade/upgrade node versions on the fly by using this tool.

Usage:

nvm -v
nvm install vX.Y.Z
nvm ls
nvm list available
nvm use X.Y.Z
Steelmaker answered 3/5, 2023 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.