I know this question has been asked many times but I couldn't still do it.
So I wrongly installed "node" doing sudo apt-get install node And later I installed nodejs (v0.10.37). I tried to update to v0.12 with npm but it keeps saying 0.10.37 when I do the nodejs -v. Also, I can't use the node command since i wrongly installed the other "node thing" before.
I tried all the different commands that the people talks about in all the other answers and I couldn't do it yet.
I think the main problem is that I keep having the wrong node package and installing the nodejs-legacy doesn't work.
Also the npm install command works and creates the folder with the files but my App still says that the libraries are missing.
解决方案sudo apt-get remove nodejs
sudo apt-get remove npm
Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a
sudo apt-get update
Check for any .npm or .node folder in your home folder and delete those.
If you type
which node
you can see the location of the node. Try which nodejs and which npm too.
I would recommend installing node using Node Version Manager(NVM). That saved a lot of head ache for me. Because you can install nodejs and npm without sudo using nvm.