nvm icon indicating copy to clipboard operation
nvm copied to clipboard

Feature Request: npm management?

Open fresheneesz opened this issue 8 years ago • 14 comments

Nvm installs node and npm for a particular user, but the version of node and npm are linked. It would be nice if there was a way to choose a different version of npm, in the same way you can change your node version. It seems like the easy and recommended way to update npm is via npm install npm -g, but this installs npm globally. If you don't have the need or ability to do a global install, it would be nice if nvm could install a newer/different version for you.

fresheneesz avatar Jan 12 '16 23:01 fresheneesz

@fresheneesz install npm 2 globally, and npm install -g npm3. Is there a different use case?

Also, npm install -g npm is absolutely the only way npm should be installed - nvm makes that "global" install contained within the nvm-installed node, however. When using nvm, you should never need sudo, and should always be able to npm install -g anything you like.

ljharb avatar Jan 13 '16 00:01 ljharb

@ljharb Wait, so you're saying that if I have npm installed via nvm, doing a global npm install -g won't require sudo and will only be available to the calling user? That definitely solves the sudo issue, but the problem of consistent version management still exists. If you update npm, then use nvm to change the version of node, your npm version will be changed again, right?

fresheneesz avatar Jan 13 '16 00:01 fresheneesz

Yes, that's the whole point of nvm - you NEVER need sudo.

And yes, npm follows the node version - so if you want a version everywhere, you'd need to upgrade it in each version by running npm install -g npm@version.

ljharb avatar Jan 13 '16 01:01 ljharb

So, if I want to install the latest npm 3.7, what is the "matching" node version? The way I see it, there is no way to get npm 3.7 within nvm

mikeerickson avatar Feb 04 '16 18:02 mikeerickson

That is true, it doesn't yet ship with any node version. so npm install -g [email protected] would do it, in each node version you want it available.

ljharb avatar Feb 04 '16 18:02 ljharb

@ljharb ah so switch to version of node (nvm use 5.5) and then use npm install -g [email protected]

mikeerickson avatar Feb 04 '16 23:02 mikeerickson

yup!

ljharb avatar Feb 04 '16 23:02 ljharb

I found this info very useful. Perhaps it should be in the readme?

Cohen-Carlisle avatar Mar 11 '16 16:03 Cohen-Carlisle

it would be really nice to have an option for the npm version in .nvmrc so that everyone on a team can install the same versions

trickpattyFH20 avatar May 10 '18 20:05 trickpattyFH20

I got something working pretty well that allows you to switch npm versions without having to reinstall a new version everytime you want to switch:

https://github.com/ORESoftware/npm.version

ORESoftware avatar Jun 22 '18 08:06 ORESoftware

i've been thinking about the same thing as @trickpattyFH20 mentioned quite a bit lately. my team relies heavily on the .nvmrc that we version with each project in order to stay in sync. a big part of this is npm version in addition to node, especially since we see value in lockfiles and different versions of npm managing the same lockfile causes lots of thrash. i've even gone as far as contributing to the npm cli to allow us to disable the upgrade encouragement so that we don't confuse team members wanting to stay up to date.

however, this means that we are currently limited to the version of npm that ships with each node version. plus, since some of our app deployment targets don't yet support latest node versions (cloud functions still only have 8 in beta and app engine standard is locked to 8 for now), we can't leverage the latest npm versions without trying to coordinate manual upgrades across the team and ci.

i imagine enabling independent management of npm certainly wouldnt be a simple change from the current approach, but hopefully some details about why we would see it as useful is helpful. maybe there is already a part of nvm that i'm overlooking that would get us closer?

travi avatar Jul 24 '18 13:07 travi

I definitely see why it would be useful (thanks for adding your use case); the challenge is how to implement it, and to find the time to do so.

ljharb avatar Jul 24 '18 15:07 ljharb

totally fair.

thanks for all the work you invest in nvm. we would be in a very different situation without the help gained from nvm (and your other tools)

travi avatar Jul 24 '18 18:07 travi

as a workaround I may propose adding short script as preinstall script in package.json:

"preinstall": "npm ls -g \"npm@>=8\" | grep \"(empty)\" && npm install -g npm@8"

Then running npm install will ensure we use npm of some version range

skyboyer avatar Jul 01 '22 21:07 skyboyer