Mark B Mark B - 12 days ago 7x
Node.js Question

Installing nodejs and npm on linux

I have having a bit of an issue with installing nodejs and npm on my linux server (which is a pi running raspbian). I had everything set up and running using

sudo apt-get install nodejs npm

All was fine and dandy, until I found out that apparently these versions are now old. So I removed them

sudo apt-get purge nodejs npm

Then I found the following answer (here) on SO and ran

curl -sL | sudo bash -
sudo apt-get install -y nodejs

Running node -v have me version 0.6.19...which I'm assuming translates to version 6.19 as opposed to version 0. However, running npm -v told me that it was not installed. So I once again purged nodejs, and looked for another solution. At which point I decided to follow the stuff on nodejs's site (here). And I ran the following commands.

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs


sudo apt-get install -y build-essential

2 issues:

1) The version installed was still 0.6.19. I would rather have version 4.x, since that's what I'm running on my dev machine (macOS Sierra).

2) I still don't have npm. Which renders nodejs useless

Any help on either (but preferably 2) would be great. Thanks in advance.


I really recommend you install node and npm using nvm. This is the fastest, cleanest and easiest way to do it.

That way, you install NVM simply doing:

curl -o- | bash

To test that nvm was properly installed, close and re-open Terminal and enter nvm. If you get a nvm: command not found message, your OS may not have the necessary .bash_profile file. In Terminal, enter touch ~/.bash_profile and run the above install script again.

And you are now able to install node typing:

nvm install <version>

For example

nvm install 4.2.1