nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
79.02k stars 7.91k forks source link

Feature Request: npm management? #964

Open fresheneesz opened 8 years ago

fresheneesz commented 8 years ago

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.

ljharb commented 8 years ago

@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.

fresheneesz commented 8 years ago

@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?

ljharb commented 8 years ago

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.

mikeerickson commented 8 years ago

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

ljharb commented 8 years ago

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

mikeerickson commented 8 years ago

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

ljharb commented 8 years ago

yup!

Cohen-Carlisle commented 8 years ago

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

trickpattyFH20 commented 6 years ago

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

ORESoftware commented 6 years ago

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

travi commented 6 years ago

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?

ljharb commented 6 years ago

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.

travi commented 6 years ago

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)

skyboyer commented 2 years ago

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