Computing stuff tied to the physical world

DIJN.08 – Set up Node.js and Redis

In Uncategorized on Feb 15, 2013 at 00:01

Welcome to the eighth instalment of Dive Into JeeNodes. Let’s install Node.js!

(Note: these instructions have been updated to use the Feb 9th Raspbian image)

Now that the basic Wireless Sensor Network is up and running, it’s time to start thinking about the server-side software, which in this series will be HouseMon. For that, we need to get three pieces of software up and running on the RPi: Node.js, Redis, and git.

Those last two are in fact very easy to install on Linux, because they are available via the apt/aptitude package manager. And while we’re at it, let’s update all packages to the latest version. Getting the latest updates is always a good idea on Linux – just type:

    sudo apt-get update && sudo apt-get upgrade

Hit return when asked whether you want to install the updates. The first time around, this is bound to take some 15..30 minutes, as the system may not have been updated for quite some time, but later in it should normally takes no more than a few minutes.

Ok, back to the task at hand, i.e. installing redis and git:

    sudo apt-get install redis-server git

Easy, eh? Welcome to the world of open source Linux software. There are over 35,000 packages available. One way to explore what there is, is to use the menu-based “aptitude” command (type “sudo aptitude” if you’re curious, but be careful what you wish for!).

With Node.js, things are a bit more complicated, because the current version of “Node” available via apt-get is a bit too old for us. Fortunately, we don’t have to go through an actual build from the source code, as I described last month (things move fast in this world!). There is now a pre-compiled version of Node which we can install fairly easily:

  • First, a preparatory step, enter:

    sudo usermod -aG staff pi && sudo reboot

    Don’t be alarmed by the reboot, it’s merely a lazy way to log out and back in, which is essential for this one-time configuration change of the RPi. Wait a minute or two, and then you can log back in via ssh, as usual.

  • Now, enter these commands exactly as shown below:

    curl$v/node-$v-linux-arm-pi.tar.gz | tar xz
    cp -a node-$v-linux-arm-pi/{bin,lib} /usr/local/
    rm -r node-$v-linux-arm-pi
    npm -v

(Note: ignore the “preserving times for …: Operation not permitted” error messages)

That’s it. You can copy and paste these commands line by line, or all in one go – the latter is usually more convenient. The final “npm -v” command verifies that “node” and “npm” work properly by reporting npm’s version number when you hit return, i.e. “1.3.x”.

Lots of powerful tools… all in preparation of being able to install and use HouseMon.


(This series of posts is also available from the Dive Into JeeNodes page on the Café wiki.)

  1. HI all,

    I needed to add an sudo in front of the rsync command, like:

    sudo rsync -a node-$v-linux-arm-pi/{bin,include,lib} /usr/local/

    as the /usr/local directories are not writable by an ordinary user :-))

  2. Hello,

    did the “sudo usermod -aG staff pi && sudo reboot” step, but had also to add the “sudo” in front of the “rsync” command line. Thank you for all the great work here!

  3. Got my raspberry today. Got the same messages as Rudi, dit not skip the “sudo usermod -aG staff pi && sudo reboot” step.

    Although i got the 1.2.10 the first time, reinstalled as Rudi indicated…

  4. Hi JCW I am trying to use a ASUS Netbook instead of the Pi as I had the Netbook already and has built in wifi, battery backup and would prefer not to have the expense of a Pi.

    I have loaded Jolicloud (uses ubuntu) version of Linux, it seems to work ok.

    Have downloaded the ubuntu version of nodejs, have been able to follow and modify your statements up to the rsync statement.

    My limited knowledge of Linux has stopped me. The word -linux-arm-pi has been ommitted because of the (Jolicloud ubuntu) version of Linux , my username is len

    rsync -a node-$v(-linux-arm-pi)/{bin,include,lib} len (/usr/local/)

    Problems start to occur here- such as permissions denied and missing stuff which I don’t understand.

    I suppose I will have to get a Pi, but it would be good to use the Netbook if possible.

    Any chance you could include the generic version of nodejs installation as well as the Pi version.

    • No worries, we’ll get that working – but it the initial series of posts I’d like to stick to a single platform.

      What do you get with “ls -ld /usr/local” – and what is the output you see from the command “id”?

  5. Ok, I need some help here – we ought to be able to resolve this with a few people chiming it: what do you get when you do “ls -ld /usr/local” ? The logic in the above article is that /usr/local is owned by root with write permissions for user “staff”. The usermod thing was to make sure that default user “pi” also gets added to that group. Using sudo for the rsync will work, but masks a bigger problem that all future installs to /usr/local will also have to use sudo. The usermod trick solves that once and for all – once it works properly, that is…

  6. drwxrwsr-x 10 root staff 4096 Aug 15 2012 /usr/local

    • Thx – that’s what I have here, and why the above post worked for me exactly as described.

  7. Another point of interest might be the output of ‘grep pi /etc/group’ and ‘grep staff /etc/group’

    • Good point – I’m still puzzled by the fact that we’re running into difference at all at this point. Where and why are some people’s setups diverging from the one described so far?

  8. JCW My Netbook running Jolicloud (ubuntu) is finally up and running with Nodejs. v0.8.19 The npm returns 1.2.10 ok so I hope to continue with you on this exciting journey.

    • Excellent – I’m still curious about what you get with “ls -ld /usr/local” – and the output from the command “id”.

  9. Tonite I prepared a fresh SD card (on my Mac) of 2012-12-16-wheezy-raspbian.img

    Then I followed your instructions very carefully, and yet I too had to add sudo in front of the rsync. Oh well… I don’t think it matters, but in case you are curious –

    see below, actual cut and paste from my terminal window…

    pi@rasp22d4 ~ $ sudo usermod -aG staff pi 
    pi@rasp22d4 ~ $ sync
    pi@rasp22d4 ~ $ shutdown -r now
    pi@rasp22d4 ~ $ v=v0.8.19
    pi@rasp22d4 ~ $ cd
    pi@rasp22d4 ~ $ curl$v/node-$v-linux-arm-pi.tar.gz | tar xz
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 4254k  100 4254k    0     0  1354k      0  0:00:03  0:00:03 --:--:-- 1398k
    pi@rasp22d4 ~ $ rsync -a node-$v-linux-arm-pi/{bin,include,lib} /usr/local/
    rsync: failed to set times on "/usr/local/bin": Operation not permitted (1)
    rsync: failed to set times on "/usr/local/include": Operation not permitted (1)
    rsync: failed to set times on "/usr/local/lib": Operation not permitted (1)
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
    pi@rasp22d4 ~ $ sudo rsync -a node-$v-linux-arm-pi/{bin,include,lib} /usr/local/
    pi@rasp22d4 ~ $ rm -r node-v0.8.19-linux-arm-pi/
    pi@rasp22d4 ~ $ ls -ld /usr/local
    drwxrwsr-x 10 root staff 4096 Dec 15 11:31 /usr/local
    pi@rasp22d4 ~ $ grep pi /etc/group
    pi@rasp22d4 ~ $ grep staff /etc/group
    pi@rasp22d4 ~ $ exit

  10. It looks from William’s post that you are able to copy the files but not set their times. Normally only the owner of a file can change its times, but it probably doesn’t actually matter if the times are copied in this situation. You could try doing rsync -a --no-times ... to ignore copying the times.

  11. On a fresh install of raspbian dated 2013-02-09 there was no rsync installed.

    Of course it is easily solved by:

    sudo apt-get install rsync

    • Ah – good to know. Did you check this after installing redis-server and git, or before? I have this vague memory that one of them also included rsync, but I may well be wrong after all these recent installs.

  12. You maybe right. When trying to download housmon I discovered that I forgot to install git. So it can very likely be a dependency of git. I only discovered this after placing my comment. We probably better remove my comments not to confuse others.

    • Confirmed, just now: rsync will be included when you install redis-server + git (most probably git).

  13. Why use rsync instead of mv or cp?

    • Yep, I’ve switched to “cp -a”, but can also confirm that rsync isn included when installing redis-server + git.

Comments are closed.