I've been using NVM to install the latest versions of Node.js for my Node.js work. It works totally fine for installing separate versions and switching between them. It also installs the latest version of NPM within each local .../bin folder along with the Node.js binary. However, there doesn't seem to be a way to switch the version of NPM that I'm using (or at least I can't figure it out).
The only solution I can think of myself is to delete the binary that it's defaulting to (which is the NPM that was installed when I first installed node with NVM), and in its place to put the latest NPM binary. However, is there a better way to go about doing this?
nvm now has a command to update npm. It's nvm install-latest-npm or nvm install --latest-npm . nvm install-latest-npm : Attempt to upgrade to the latest working npm on the current Node. js version.
For switching to different versions that are already installed you can use the following commands for different scenarios: nvm use node #uses latest Node. js version available on server. nvm use --lts #This will switch to the latest LTS version nvm use 14.15.
nvm manages node. js and npm versions. It's designed to be installed per-user and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
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-npm
ornvm 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.
Use
npm install [email protected] -g
npm install [email protected] -g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With