How can I change the version of npm using nvm?
Use
npm install [email protected] -g
npm install [email protected] -g
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.
nvm now has a command to update npm. It's nvm install-latest-npm
or npm install --latest-npm
.
nvm doesn't handle npm.
So if you want to install Node.js 0.4.x (which many packages still depend on) and use NPM, you can still use npm 1.0.x.
Install Node.js 0.6.x (which comes with npm 1.1.x) and install nvm with npm:
npm install nvm
. ~/nvm/nvm.sh
Install Node.js 0.4.x with nvm:
nvm install v0.4.12
nvm use v0.4.12
Install npm using install.sh (note the -L
parameter to follow any redirects):
curl -L https://npmjs.org/install.sh | sh
This will detect Node.js 0.4.12 and install npm 1.0.106 in your ~/nvm/v0.4.12/lib/node_modules folder and create a symbolic link for nvm:
~/nvm/v0.4.12/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js
If you try to run npm, it will still give an error, but if you do nvm use v0.4.12
again, it should now work.