简体   繁体   中英

Update NPM to custom version on NVM + homebrew

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?

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM