Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: npm management? #964

Open
fresheneesz opened this issue Jan 12, 2016 · 14 comments
Open

Feature Request: npm management? #964

fresheneesz opened this issue Jan 12, 2016 · 14 comments
Labels
feature requests I want a new feature in nvm!

Comments

@fresheneesz
Copy link
Contributor

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
Copy link
Member

ljharb commented Jan 13, 2016

@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
Copy link
Contributor Author

@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
Copy link
Member

ljharb commented Jan 13, 2016

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
Copy link

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
Copy link
Member

ljharb commented Feb 4, 2016

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.

@mikeerickson
Copy link

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

@ljharb
Copy link
Member

ljharb commented Feb 4, 2016

yup!

@Cohen-Carlisle
Copy link

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

@ljharb ljharb added the feature requests I want a new feature in nvm! label Mar 11, 2016
@trickpattyFH20
Copy link

trickpattyFH20 commented May 10, 2018

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

This comment has been minimized.

@travi
Copy link

travi commented Jul 24, 2018

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
Copy link
Member

ljharb commented Jul 24, 2018

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
Copy link

travi commented Jul 24, 2018

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
Copy link

skyboyer commented Jul 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm!
Projects
None yet
Development

No branches or pull requests

8 participants