Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'm new to using node and I didn't find any solution to such an error online

like image 309
Pragati Basa Avatar asked Jul 08 '17 16:07

Pragati Basa


People also ask

Why npm command is not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

How do I start npm in Ubuntu?

Adding execute permissions to the "start" script. Removing all node modules, reinstalling node, re-creating the project file. Editing package. json to include the start script.

How do I use npm in Ubuntu?

If you run into any issues with npm being unable to update because it's not installed, you can install npm first by using sudo apt-get install -y npm , then run the command above to update it. sudo apt install build-essential . And that's it! You've got the latest versions of NodeJS and NPM on your Ubuntu machine.


2 Answers

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

like image 124
baao Avatar answered Sep 18 '22 10:09

baao


This worked for me on Ubuntu 18.04:

sudo apt install nodejs
sudo apt install npm
like image 36
Nelu Avatar answered Sep 17 '22 10:09

Nelu