Thursday, 8 May 2014

Install node.js on Raspberry Pi

I decided to run a version of a node.js web app I'm developing on a Raspberry Pi. This post describes how to install node.js on a Raspberry Pi. It also services as one way to get node.js up and running on any Linux box.

I'm starting with a Raspberry Pi running the RaspBian operating system and I'm looking at the command prompt. A precompiled version of node.js is not available for the Raspberry Pi (AFAIK) so we need to get the node.js source code and compile it. If you're using Windows, Mac or Linux you're probably best off going to the node.js homepage and clicking the Install button.

Update Raspbian and install tools

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install git-core build-essential python libssl-dev nano

Get the Node repository from github

sudo git clone
cd node
sudo git checkout v0.10.26
The checkout step is where you choose the version to install, the latest version is shown on the node.js homepage. The files in the folders tree are all changed to match the version checked out (git is wonderful isn't it?)

Compile and install node.js

I feel I should warn you that the Raspberry Pi takes a loooong time to compile node.js. The sudo make step below took over two hours thirty minutes to complete.
sudo ./configure
sudo make
sudo make install
sudo python ./tools/
Then all I had to do was git clone my web app, npm install and get it running. 

If you'd like a play around you should read my blog post: Build a node.js bootstrap site in 30 minutes.