How to update npm

2019-01-29 23:59发布

I'm trying to install mean.io boilerplate. It fails when running sudo npm install -g meanio@latest. Prior to failing it notes that it 'wants' npm version 1.4.x, whereas I have 1.2.18 installed. So I tried updating npm to the latest; several ways. Last of which was...

ubuntu@ip-xxx-xx-xx-xxx:~$ sudo npm install -g npm
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm@1.4.7 /usr/local/lib/node_modules/npm

ubuntu@ip-xxx-xx-xx-xxx:~$ npm --version
1.2.18

Why is it still showing version 1.2.18, when I just updated to 1.4.7?

标签: ubuntu npm
15条回答
叛逆
2楼-- · 2019-01-30 00:37

if user3223763's answer doesn't works, you can try this:

sudo apt-get remove nodejs ^node-* nodejs-*
sudo apt-get autoremove
sudo apt-get clean
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs

Then :

curl https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | sh

After this, open a new terminal and check the npm version:

npm --version

EDIT / UPDATE :

Today the last nvm version is :

https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh

Thus the CURL command is: v0.25.4 instead of v0.13.1

curl https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | sh

You can check https://github.com/creationix/nvm/releases to use the correct version for further upgrades

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-30 00:39
nvm install-latest-npm

if you happen to use nvm

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-30 00:40

Check your node version node -v and your npm version npm -v Then To update your npm, type this into your terminal : sudo npm install npm@latest -g

N.B: Debian Based OS{ubuntu or Linux mint}

查看更多
太酷不给撩
5楼-- · 2019-01-30 00:43

upgrading to nodejs v0.12.7

 # Note the new setup script name for Node.js v0.12
 curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

 # Then install with:
 sudo apt-get install -y nodejs

Source from nodesource.com

查看更多
放荡不羁爱自由
6楼-- · 2019-01-30 00:44

To get the latest stable version just run

npm install npm@latest -g

It worked just fine for me!

查看更多
走好不送
7楼-- · 2019-01-30 00:50

Looks like you are using Ubuntu (from the command line you show). To update npm and nodejs you can use the PPA repository:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
查看更多
登录 后发表回答