3

Trying to update/change to a specific NPM version on NVM installed via homebrew

(Would be very useful when beta testing, currently NPM v3.0.x)

Doing it out of NVM I ran npm install -g npm@3.0-latest

In NVM I update to the current latest node version via nvm install v0.12.7 but this comes bundled with npm v2.11.3. Obviously as it is the latest stable version of NPM.

Is there a way to select/install which version of NPM you want to use in NVM?

cmdv
  • 1,693
  • 3
  • 15
  • 23
  • possible duplicate of [How can I change the version of npm using nvm?](http://stackoverflow.com/questions/9755841/how-can-i-change-the-version-of-npm-using-nvm) – suish Aug 18 '15 at 09:56
  • that answer isn't very specific to -version number though `curl https://npmjs.org/install.sh | sh` what would be the link to a specific version required if so? – cmdv Aug 18 '15 at 10:01

3 Answers3

7

you just switch to the desired node version with nvm and then just execute:

npm install -g npm@1.4.3 

being 1.4.3 the desired npm version

to see different versions you can use:

npm view npm
edsadr
  • 1,087
  • 6
  • 17
  • I'm not having any luck as I did try this solution. `npm install -g npm@3.2.2` and I get the output `/Users/cmdv/npm/bin/npm -> /Users/cmdv/npm/lib/node_modules/npm/bin/npm-cli.js npm@3.2.2 /Users/cmdv/npm/lib/node_modules/npm` then `npm -version` I get `2.11.3` which is what node v0.12.7 comes packaged with, so no luck here. It doesn't seem to be overriding the NVM version. – cmdv Aug 18 '15 at 21:12
  • Not really sure why is not working for you, check this screenshot where I downgraded npm use those instructions: https://cloudup.com/cp2MwXbtTxO – edsadr Aug 18 '15 at 21:56
  • Ah cool, do you think because you're using io.js is the reason it's working and not with node? I'll give it a try – cmdv Aug 19 '15 at 08:37
  • No, works the same with Node... https://cloudup.com/caFty77ff2s , I think maybe your problem is with nvm version, not trusting the install by brew at this moment, check this answer: http://stackoverflow.com/questions/32069548/nvm-cannot-load-default-node-with-default-alias-set/32072238#32072238 you could give it a try – edsadr Aug 19 '15 at 12:34
2

In case you using nvm, node and npm ware installed as couple into the nodeVERSION directory. for example C:\Users\user\AppData\Roaming\nvm\v8.11.1

So in case that you want to upgrade npm version in specific node version all you need to to is: to copy dir node_modules/npm from the nodejs location, remove the npm bin and cmd, and run node npm-cli.js i -g npm@latest inside bin dir in the copied folder.

For understanding, in case you update npm using specific node version through nvm it'll be specific update of npm to the node version.

for instance: you have two versions of node: 1) v8.11.1 2) v9.8.0

In both of them npm version 5.8.0 installed.

In case you are using option 1 (version v8.11.1) and you want to upgrade npm version to npm 6.0.0 (using npm command npm i -g npm@6.0.0) the upgrade will be only for node option 1 and not for option 2.

So remember in case you switch back to option 2 the npm version will be 5.8.0.

Alon Asulin
  • 109
  • 1
  • 3
0

Step 1) Clear the npm cache:

sudo npm cache clean -f

Step 2) Install the node helper application called "n":

sudo npm install -g n

Step 3) Install the specific version that you want, eg: for v12.14.1:

sudo npm v12.14.1

Alternatively, to just update to the latest stable node version:

sudo n stable

Step 4) Confirm that you are running the desired version:

node -version

or

node -v

Reference: Code Geek: How to Update Node to Any Version using Npm

Kmeixner
  • 1,664
  • 4
  • 22
  • 32