Npm command not working on ubuntu

I installed node and npm on Ubuntu 14.04, and when I try to use any npm command, I get the following error:

/usr/local/lib/node_modules/npm/lib/config/cmd-list.js:113
module.exports.aliases = Object.assign({}, shorthands, affordances)
                            ^
TypeError: Object function Object() { [native code] } has no method 'assign'
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/cmd-list.js:113:33)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /usr/local/lib/node_modules/npm/lib/npm.js:37:17
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:471:3)
at Module._compile (module.js:456:26)

I am new to using node and I have not found a solution for such an error on the Internet

+4
source share
4 answers

Most likely, you are running the old version of node.js (check with node -v, at the time of writing this, the last lts is 6.x). I suppose you tried to install it using apt-get install nodejsor similar. The packages shipped with ubuntu 14 are deprecated, follow the recommendations on the nodejs' download page and follow these steps:

Step 1, remove the old packages:

sudo apt-get remove --purge nodejs

2, :

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

​​ nodejs, ES6, Object.assign

+28

npm ,

nodejs,

sudo apt-get remove nodejs

sudo apt-get remove npm

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

package-manager

0

npm ,

nodejs,

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

,

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

,

0

Ubuntu 18.04:

sudo apt install nodejs
sudo apt install npm
0

Source: https://habr.com/ru/post/1681023/


All Articles