Installing and using node.js on Raspberry Pi

The programming language landscape is always changing, and in my "day job" as a software developer I use a wide range of languages. Over the last year or so I can remember working with Awk, C, C++, Java, JavaScript, Ruby, shell script and SQL. And that's not counting all the specialist configuration, scripting and data languages. Although there is still a lot of jobs looking after enterprise systems written in the likes of C, C++ and Java, I am also seeing more and more development being done in more dynamic languages. In particular, the rising star seems to be node.js.

If you are not familiar with node.js I recommend giving it a look. It's JavaScript, but running on a server rather than in a browser. It's free, runs on most systems, easy to work with, surprisingly fast, and has a wide array of third-party software available though its npm package management system.

Running such software on a generic server is all well and good but, naturally, I want to be able to build systems using node.js and Raspberry Pi. I looked around and found an article from "Josh On Design" which got me part of the way, but it did seem a bit vague about a couple of the steps, so I thought I'd describe how I got things set up for a project I'm currently working on.

As always, the first step is to get a Raspbian image on an SD card. I don't think node.js is particularly picky, and should run on any reasonably recent version. For this project I started with a clean SD card with the latest Raspbian version (2014-01-07 at the time of writing). To install this software you will need a command line. I prefer to connect to the Raspberry Pi over ssh (using my favourite tool MobaXterm), but if you want to use a keyboard and screen attached to the Raspberry Pi you will need to open a terminal window.

If you are concerned that your Raspbian might be getting a bit old, you may want to refresh it using:

sudo apt-get update
sudo apt-get upgrade

This is usually a good idea, but if you have specific versions of other software installed, or are just in a hurry, you can skip to the next step.

As Josh points out, compiling a modern programming language and toolset from scratch takes a long time on a little Raspberry Pi, so the node.js team are now providing downloadable versions pre-built for the Pi. Unfortunately, they don't seem to build these for every released version, so you can't always just grab the latest. All the downloads are available from, and I found I needed to start with latest and work backwards through the versions until I found one with linux-arm-pi in its name. At the time of writing, this is version 0.10.25. Once you have found a recent Raspberry Pi build, you need to download it and install it on the Pi. I decided to install it to /opt/node as follows. Of course, if you have chosen a different version, you will need to change the names.

sudo su -
cd /opt
tar xvzf node-v0.10.25-linux-arm-pi.tar.gz
ln -s node-v0.10.25-linux-arm-pi node
chmod a+rw /opt/node/lib/node_modules
chmod a+rw /opt/node/bin
echo 'PATH=$PATH:/opt/node/bin' > /etc/profile.d/

The ^D at the end indicates pressing Control-D to exit the root shell and return to your regular user.

Once you have done this installation, either logout and log back in, or open a new terminal session and enter node --version which should show the version you have installed. You can also try npm --version, which will tell you the version of npm. Now, whenever you start the system, you will have access to node and npm.

One final step is to install node-gyp. This is not strictly necessary in every case, but you will find it useful if you ever need to build and install any "native" npm modules.

npm install -g node-gyp

That should be enough for now. I will cover some useful things to do with node.js in a future article.

No related content found.


  1. Pingback: Install and use Node.js on the #RaspberryPi | Raspberry PiPod

  2. I can confirm this tutorial works on the latest arch linux version for 12/6/14. I also found that the lastest node version at the time was v0.11.12 many thanks for the tutorial

  3. I believe the order of “upgrade” and “update” for “sudo apt-get” should be reversed. You need to update your local database of packages before you can upgrade any installed packages with changes.

    Otherwise a nice tutorial.

  4. Pingback: First demo of my display screen project coming up | Raspberry Alpha Omega

  5. Pingback: Setting up a website for your home (Part 1) | NoteJS

  6. Pingback: Backup your Xbox One Game DVR videos to a Raspberry Pi or anywhere | Pete's Documentation Emporium

  7. I keep getting this error and I cant figure out why I cant get past this. The original tutorial is from here:
    But I cant get any feedback about my mistakes. Am I better off just installing MEAN.js ?

    Please Help

    Error: Cannot find module ‘express’
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object. (/home/geekmonster/projects/node/server.js:1:84)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

    • This usually indicates that you have not installed the ‘express’ npm module. I note that on the page you mention it states:

      Next, I installed ExpressJS:
      npm install express

      Is it possible you accidentally skipped this step? Or possibly installed it while you were in the wrong directory?

      If either of these is the case you could try

      npm install -g express

      which will install it for all applications.

      • Hello Frank
        thanks for the reply.
        what had happened was:
        1.) I installed express inside the opt folder instead of the home folder
        2.) I was trying to start up the server outside of the node folder.

        Now as far as my projects folder. could I place all my IoT projects inside (side by side) in this folder?
        And do you have any tuts on creating my own dashboard for like lets say a different icon for each task inside and outside my house, and accessing them through by use of sockets and what not.

        • Node.js is pretty flexible about where you put your projects. Each Node.js project is just a folder with a typical structure inside it: a file package.json with project metadata, dependencies etc. and a folder node_modules where third-party code is installed when you use npm install. So feel free to put several of these in one “workspace”.

          I’ve not done a dashboard like that myself, but I’ll have a look around. Sounds like fun!

Leave a Reply

Your email address will not be published. Required fields are marked *