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

Switching node version changes installed npm #210

Closed
jarrodldavis opened this issue Dec 22, 2014 · 16 comments
Closed

Switching node version changes installed npm #210

jarrodldavis opened this issue Dec 22, 2014 · 16 comments

Comments

@jarrodldavis
Copy link

Not sure why, but whenever I change the node version using n, my global npm is reverted to an old version and I have to run npm install npm@latest -g every time I switch. Is there a way I can tell n to ignore whatever internal npm it is using?

@tjwebb
Copy link
Collaborator

tjwebb commented Dec 22, 2014

npm is bundled with node. It will switch to whichever npm version was bundled with the node version you switch to.

@dstroot
Copy link

dstroot commented Jan 2, 2015

Actually the issue as I see it is that it seems impossible to keep npm updated properly - the npm version is "locked" to the node version it was installed with!

For example if I install n stable I have npm version 1.4.28. I then update npm to 2.1.7. Then I switch to a different version of node and npm switches also. OK I get that... but if I switch back to n stable I am back at 1.4.28 again.

There must be some way to update npm and have it stick, right? Otherwise I can't use this amazingly handy utility. :(

@dstroot
Copy link

dstroot commented Jan 2, 2015

node and npm seem to be going their separate ways. Here's how to decouple completely.
Now you can switch node versions with n all day and npm will remain stable as well as your global
modules. Cheers:

# save a list of what is installed globally
npm -g ls --depth=0 > npm_global_packages.txt

# Make a directory for global installations:
mkdir ~/.npm-global

# Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
# NOTE: add this to your profile as well:
export PATH=~/.npm-global/bin:$PATH 
npm install npm -g
echo "NPM global directory changed: $(npm config get prefix)"

# Remove old npm
sudo rm /usr/local/bin/npm
sudo rm -rf /usr/local/lib/node_modules

# Now reinstall any global npm modules using the list we created above

@webdesserts
Copy link

Perhaps with the changes suggested in #212. Now would also be a good time to introduce a similar command such as n npm 2.1.7 as well?

@Globegitter
Copy link

Yep it would be great to be able to switch npm separately. Most of the time having to do npm i -g npm seems a bit cumbersome.

@maxrimue
Copy link
Contributor

maxrimue commented Mar 8, 2015

I think all we have to do is to tell n to only copy /lib/node_modules/npm from the downloaded Node.js package if it's not already installed, right?

@ghost
Copy link

ghost commented Mar 8, 2015

What about npmbrew?

@Globegitter
Copy link

Oh yeah, at a first glance npmbrew does look pretty good.

@tjwebb
Copy link
Collaborator

tjwebb commented Mar 10, 2015

Actually the issue as I see it is that it seems impossible to keep npm updated properly - the npm version is "locked" to the node version it was installed with!

I'm not convinced that using newer npm with older node will cause you any fewer problems than using older npm with newer node. The safest way to go is going to be to use the npm bundled with your node version, especially since whoever else is to npm install your thing likely is going to have the bundled version of npm, not your special version that you like.

@bigdx
Copy link

bigdx commented May 20, 2015

I found it more annoying that "npm list -g" throws a lot of errors (invalid/extraneouse mostly) after I changed node-version thru n ...
Solutions ...
A) Update to latest npm:
npm update -g
B) Reinstall the existing npm-version:
npm install -g npm@VERSION

But why I have to do that?

Funny fact: As root "npm -v" always returns the version of the RPM i installed to install node/n ... for every other user "npm -v" works as expected ...

@cades
Copy link

cades commented May 3, 2016

+1, because npm3 breaks some of my project, so I need to downgrade to npm2 every time I switch.

@ghost
Copy link

ghost commented May 3, 2016

@cades Hmm, well, if you happen to be using fish-shell, check out fnm for a native solution. Else, you'll either have to use nvm or nave.

@cades
Copy link

cades commented May 3, 2016

@bucaran thanks for suggestion! I'll give nave a try. But I'm still wondering why n can not do this? Is it possible to add this feature (even break the backward compatibility)?

@Jonnymcc
Copy link

Related #364

@shadowspawn
Copy link
Collaborator

This issue has not had any activity in over six months. It isn't likely to get acted on due to this report.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

@shadowspawn
Copy link
Collaborator

For future visitors to this page, please note that there is now support for preserving the npm install when installing node. See --preserve and N_PRESERVE_NPM:

https://github.com/tj/n#preserving-npm

Repository owner deleted a comment from AkroutiHamza Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests