npm command not working on ubuntu

☆樱花仙子☆ 提交于 2019-12-04 09:22:41

You are most likely running an old version of node.js (verify with node -v, at the time of writing this, the latest lts is 6.x). I suppose you tried to install it with apt-get install nodejs or similar. The packages shipped with ubuntu 14 are outdated, follow the advice on nodejs' download page instead, and do the following:

Step 1, remove the old packages:

sudo apt-get remove --purge nodejs

Step 2, type the following commands one after the other and follow the screen:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Now you have a version of nodejs installed that allows ES6 methods, as Object.assign is one of them

npm might be older version,

so remove nodejs,

sudo apt-get remove nodejs
sudo apt-get remove npm

then,

sudo apt-get install curl #if you dont have curl

Node.js v6:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Node.js v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
Node.js 8:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

for more info, package manager

This worked for me on Ubuntu 18.04:

sudo apt install nodejs
sudo apt install npm
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!