327

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

Mike
  • 14,010
  • 29
  • 101
  • 161
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
  • 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 node – serup Feb 02 '23 at 15:44

5 Answers5

530

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 npm@3.10.10

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.

Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
  • 4
    What does `-g` mean in this case? Can you have a repo-specific version of npm? – Jim Aho Jan 16 '18 at 13:33
  • 1
    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. – Don Kirkby Jan 16 '18 at 18:09
  • 20
    g stands for global – AGrush Apr 16 '19 at 17:28
  • 1
    FYI: Make sure you do this from a cmd that has admin priv. – Seth Eden May 27 '21 at 16:50
  • 8
    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. – xarlymg89 Sep 24 '21 at 07:40
  • For some Angular packages, I needed to downgrade npm to `^7.5.6`. `npm install -g npm@7` did the trick. Thanks! – rinogo Oct 22 '21 at 19:49
  • 1
    but npm -v still prints the latest version – yılmaz Mar 22 '22 at 16:22
  • If you do get an error, you may want to sanity check your directory ownership by running the same command, but with `sudo` – T.Woody Sep 23 '22 at 15:27
  • 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 – CTS_AE Oct 13 '22 at 18:37
64

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 npm@4.6.1

It is tested on linux

Liam
  • 27,717
  • 28
  • 128
  • 190
Parvinder Kumar
  • 775
  • 5
  • 8
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.

moyo
  • 1,312
  • 1
  • 13
  • 29
5

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/

Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131
  • 1
    You can find the node.js with a specific version of npm by searching in [Looking for latest release of a version branch?](https://nodejs.org/en/download/releases/#looking-for-latest-release-of-a-version-branch). – li ki Oct 02 '21 at 02:09
  • This is the correct answer, npm is tied to the node version – Liam Mar 01 '22 at 14:26
  • Soooo...you download the older version then you delete the newer? what are the next steps to actually running the app? – VibrationPositive Jul 20 '22 at 14:41
  • 1
    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...` – geoidesic Nov 21 '22 at 15:52
-1

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