shell - How to change Node.js version with nvm - Stack Overflow
Tip for easily switching between Node.js versions ?
node.js - How can I change the version of npm using nvm? - Stack Overflow
Is there a project level way to specify nvm versions and avoid nvm use?
Videos
nvm install 8.10.0 is for installing proposed node version locally.
In order to use it:
nvm use 8.10.0
Note that you need to run this command as administrator.
You can always set default Node.js version:
nvm alias default 8.10.0
Install
nvm install 8.10.0Use once per terminal
nvm use 8.10.0Set up as the default for all terminals
nvm alias default 8.10.0Set up Node.js version for your IDE
- For more information check nvm documentation
Hello everyone 👋
I'm quite new to the Node.js ecosystem and I've run into a problem. I'm working on a school project that requires a specific Node version (let's say v16), but at the same time, I'm trying to run a personal project I found on GitHub that only works with the latest version (v20+).
For now, my only solution is to uninstall and reinstall the correct version every time I switch projects, which is really tedious 😥
I imagine there must be a simpler way to do this. How do you easily switch between Node.js versions on your machine? Is there a 'standard' tool that everyone uses?
Thanks in advance for your help 🙏
As noted in another answer, there is now a command for this:
nvm now has a command to update npm. It's
nvm install-latest-npmornvm install --latest-npm.
nvm install-latest-npm: Attempt to upgrade to the latest working npm on the current Node.js version.
nvm install --latest-npm: After installing, attempt to upgrade to the latest working npm on the given Node.js version.
Below are previous revisions of the correct answer to this question.
For later versions of npm it is much simpler now. Just update the version that nvm installed, which lives in ~/.nvm/versions/node/[your-version]/lib/node_modules/npm.
I installed Node.js 4.2.2, which comes with npm 2.14.7, but I want to use npm 3. So I did:
cd ~/.nvm/versions/node/v4.2.2/lib
npm install npm
Easy!
And yes, this should work for any module, not just npm, that you want to be "global" for a specific version of node.
In a newer version, npm -g is smart and installs modules into the path above instead of the system global path.
Npm can install itself. Just use npm install with the global flag -g, to overwrite the version of npm currently installed.
Here's an example. (Change 5.4.0 to whichever version you want.)
npm install [email protected] -g
If you switch versions later in nvm, the npm version will change as well, so it's easy to undo this action.