Node.js on Raspberry Pi

Posted by {"display_name"=>"greg", "login"=>"greg", "email"=>"greg@udon.org", "url"=>""} on March 23, 2016 · 2 mins read

Here are the steps to install an updated version of Node.js on Raspberry Pi. As of this writing, the Raspbian image from Feb 2016 is shipping Node.js vers 0.10.29 which was released in June 2014.

Here's the page on installing Node.js on Ubuntu platforms and another page specifically on older distros including Debian Wheezy.

Remove Existing Node.js

First remove the existing Node.js and npm that was installed with Raspbian:

sudo apt-get -y remove nodejs-legacy nodejs-dev nodejs
sudo apt-get -y remove npm

Node.js Install Option #1

In March 2016, this option installed v4.2.1 and can also be used to install v0.12.6.

There's a great site on installing Node.js on Raspberry here. First download the package. For the latest release issue this command:

wget http://node-arm.herokuapp.com/node_latest_armhf.deb

For 0.12.6, download this:

wget http://node-arm.herokuapp.com/node_archive_armhf.deb

Now, install the package:

sudo dpkg -i node_latest_armhf.deb

Check on the version of node you've just installed to confirm it's working:

node -v

If it can't find Node, then it's been installed in /usr/local/bin instead of /usr/bin. Make a symbolic link:

sudo ln -s /usr/local/bin/node /usr/bin/node

Install the express, http and json-proxy modules:

sudo npm install -g http
sudo npm install -g express
sudo npm install -g json-proxy

Install Option #2

This option got me version 4.4.0 and is the approach documented on the Node Red site. Updating my apt-get cache resulted in some errors that required me to remove some additional source files in /etc/apt/sources.list.d/

curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
sudo apt-get install -y build-essential python-dev python-rpi.gpio nodejs

Besides installing a newer version of node, this version also used /etc/alternatives to manage multiple Node installs.

Option #3

In this last option, you choose the distribution from the nodejs.org distribution site. Browse https://nodejs.org/dist to see what's available.

wget https://nodejs.org/dist/latest-v4.x/node-v4.4.1-linux-armv7l.tar.gz
tar -xvf node-v4.4.1-linux-armv7l.tar.gz
cd node-v4.4.1-linux-armv7l.tar.gz
sudo cp -R * /usr/local/

json-proxy

I've started using json-proxy to address same orgin issues when using REST services from Javascript SPA applications so I installed that above. More details on the configuration I'm using can be found here.