hobenkr hobenkr - 2 months ago 15
Node.js Question

Why do I have two versions of npm

I'm trying to get set up with npm and nodejs on ubuntu server but noticed that somehow I ended up with two versions after running

sudo apt-get install nodejs npm

I know this because when I run
npm -v
, it returns
1.3.10
, while when I run
sudo npm -v
, it returns
2.3.0
. I'd like have this set up properly before I go any further. Does anyone understand why I ended up with two versions? It's my understanding that installing nodejs should also install npm, but this only allows me to run npm with elevated privileges which I know I shouldn't be doing. Can anyone let me know what I'm doing wrong? Thank you.

Answer

For some Linux distributions (Debian/Ubuntu and RedHat/CentOS), the latest node version provided by the distribution may lag behind the stable version. Here are instructions from NodeSource on getting the latest node.

Then you can install the latest npm by running sudo npm i -g npm@latest.