37

Is it possible to install multiple versions of npm for different projects that I am working on or are the npm installations always global? (Windows 10)

Are also tried installing different versions with https://github.com/marcelklehr/nodist but it seems to affect only the node version, not the npm version.

Or does npm version actually matter? Can I just use the newest npm version even when a project says the requirement is a certain npm version?

1
  • 1
    Re: last paragraph. Yes, the npm version may matter. There are big differences between npm 2.x and 3.x, e.g. in version 3 packages are deduped by default, which may affect some apps that expect some dependency file at a specific path in node_modules
    – TMG
    Commented Apr 3, 2017 at 13:45

5 Answers 5

50

You can install multiple versions of npm by installing multiple versions of node. To do this, you can use nvm-windows. Each different installation of node installs a different version of npm

To use a different version of node and nvm in a project, you simple need to switch:

nvm use 5.0

You can also create a .nvmrc file containing the version number in the project root directory. nvm will use the specified version of node for that project.

4
  • 2
    Thanks for the tip on .nvmrc files. I've been switching back and forth using nvm when projects require different versions and this is a huge timesaver. Commented Dec 8, 2016 at 20:27
  • @gnerkus I am using nvm but looking for npm 4.6.1 this is recommended for react native it does not seem like any of the nodes come with this version is there a workaround for this? Commented Feb 27, 2018 at 18:25
  • 3
    Say you have 2 projects using Node 10.18.0 (having "10.18.0" in their respective .nvmrc file). How would you set it up so that when working on project 1 it uses npm 7.5.0 and when using project 2 it uses npm 6.13.4 ? Commented Feb 4, 2021 at 14:27
  • I just recently ran into this issue when running npm install (old npm version of 6.x with node 16.14.0) when using nvm. I was expecting that using nvm use 16.14.0 will solve my issue (npm npm does not support Node.js v16.14.0). In VSC on Windows it threw the error, but when running npm intsall as administrator (in Cmder) it suprisingly installed everything without throwing the error. Any ideas as of why nvm (which requires admin rights) might affect this?
    – iLuvLogix
    Commented May 4, 2022 at 15:19
7

You also can install npm using npm

Example of installing specific version:

npm i -g [email protected]

2
  • 1
    You cant downgrade version of npm easily.
    – dorgan
    Commented Jun 7, 2017 at 14:50
  • @dorgan, can you provide an example, please? I have not had problems downgrading npm myself.
    – Simon
    Commented Feb 27, 2018 at 17:19
3

If you need to use a different version of npm for each project, there are a number of possible solutions. Probably the lightest-weight version is to use npx. A semi-common use-case for this can be projects that use lock-file v1 and another that uses lock-file v2. v2 was introduced in npm v7.

So in your project using lockfile v1, if you need to install a new package.

npx npm@v6 install dalle-node

For lockfile v2, or to just use the latest and great.

npx npm@latest install dalle-node

Or does npm version actually matter?

In most cases, it's not likely to matter much. The above example is one I run in to in my own projects. If you use a project and some of the npm commands are giving you trouble, e.g. npm run, try using the version of npm the project recommends before filing a bug with the maintainer.

1

if you are using eclipse IDE for Node projects, you can easily change Node version using Webclipse plugin.

enter image description here

0
0

You shouldn't look to install multiple versions of npm to manage same node packages, instead you should look to manage multiple versions of nodejs, each nodejs with bring its own minimum version of npm required with it and that's how you will get multiple versions of npm with multiple versions of nodejs. When you switch node version, the npm versions will switch automatically. To manage multiple versions of nodejs you can use nvm or n

nvm install <nodejs version>
nvm use <nodejs version>

What Thiago Caiubi mentions here is upgrading npm version within a given nodejs version . That update will happen only for that nodejs version . The corresponding npm for each of the other nodejs versions will not be touched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.