Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stolsma/3301813 to your computer and use it in GitHub Desktop.
Save stolsma/3301813 to your computer and use it in GitHub Desktop.
Working Node.js on Raspberry Pi

These instructions work for the Raspberry Pi running Raspbian (hard float) and create a hardware optimized version of NodeJS for the Raspberry PI, (and include a working install and NPM!!!):

  1. Install Raspbian - http://www.raspberrypi.org/downloads

  2. Install the necessary dependecies:

sudo apt-get install git-core build-essential

(If you just installed git then you need to administer your git identity first, else adding the patches below will fail!!!)

  1. Check out Node.js source (0.8.8 or higher):
git clone https://github.com/joyent/node.git
cd node
git checkout v0.8.8 -b v0.8.8
  1. Push four patches for V8 and OpenSSL ARM support:

The following two patches are only needed when compiling Node version <0.8.10 (already committed for 0.8.10pre NOT yet for master)

Remark: The first patch is already commited upstream to V8 cutting-edge branch (node is on a lower version of V8). The 2nd patch is pushed to the V8 bug list.

curl https://github.com/joyent/node/commit/25c2940a08453ec206268f5e86cc520b06194d88.patch | git am
curl https://github.com/joyent/node/commit/1d52968d1dbd04053356d62dc0804bcc68deed8a.patch | git am

The following two patches are only needed when compiling Node version <0.8.9 (already committed for master and 0.8.9pre + higher)

curl https://github.com/joyent/node/commit/f8fd9aca8bd01fa7226e1abe75a5bcf903f287ab.patch | git am
curl https://github.com/joyent/node/commit/7142b260c6c299fc9697e6554620be47a6f622a9.patch | git am
  1. Configure correctly and 'make':
./configure
make
  1. (Optional!) If you want to do the tests then execute (make test can't be used because the standard timeout is too low, i.e. the Rasp PI is too slow... ;-)):
python tools/test.py -t 120 --mode=release simple message
  1. Install Node and NPM in your OS:
sudo make install

NOTE on 0.8.8 tests: some tests still have issues (8 tests fail, some are timeouts (as the PI isn't that fast ;-) and one is a known bug)!

After compiling node0.8.8 the following 7 (or 8 if IPV6 is not enabled) tests will fail. After checking 3 failing tests are related to the slow processing/slow filesystems, 1 is a known bug and 3 (repl problems) are under investigation.

The following is a known bug. Will be solved in one of the next releases of Node (see joyent/libuv#526).

=== release test-os ===
Path: simple/test-os
hostname = raspberrypi
uptime = 19738.871849515
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-os.js

The Rasp Pi is not that fast that it can complete the following test in time. ;-) If time is changed from 1000 to 10000 it will complete without error...

=== release test-child-process-fork-net2 ===
Path: simple/test-child-process-fork-net2
assert.js:102
  throw new assert.AssertionError({
        ^
AssertionError: timeElasped was not between 190 and 1000 ms
    at process.<anonymous> (/home/pi/node0.8.6/test/simple/test-child-process-fork-net2.js:128:12)
    at process.EventEmitter.emit (events.js:115:20)
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-child-process-fork-net2.js

Raspbian doesn't have IPv6 enabled by default and thats where this following test is counting on. if IPv6 is enabled (sudo modprobe ipv6) this test will complete without errors.

=== release test-net-pingpong ===
Path: simple/test-net-pingpong
server listening on /home/pi/node0.8.6/test/tmp/test.sock undefined
server listening on 20988 undefined
connection: 127.0.0.1
connection: undefined
events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: listen EAFNOSUPPORT
    at errnoException (net.js:768:11)
    at Server._listen2 (net.js:891:19)
    at listen (net.js:935:10)
    at Server.listen (net.js:992:9)
    at dns.js:71:18
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-net-pingpong.js

The Rasp Pi is not that fast that it can complete the following test in time. ;-) If timeouts are changed from 10 to 100 and 20 to 200 it will complete without error...

=== release test-http-client-timeout-with-data ===
Path: simple/test-http-client-timeout-with-data
assert.js:102
  throw new assert.AssertionError({
        ^
AssertionError: 0 == 1
    at process.<anonymous> (/home/pi/node0.8.6/test/simple/test-http-client-timeout-with-data.js:30:10)
    at process.EventEmitter.emit (events.js:115:20)
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-http-client-timeout-with-data.js

The Rasp Pi is not that fast that it can complete the following test in time. ;-) If run seperately this test will complete without error!!!

=== release test-eio-race ===
Path: simple/test-eio-race
trying to kill event loop ...
could not kill event loop, retrying...
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-eio-race.js
--- TIMEOUT ---

All the following REPL test fail are under investigation (possibly due to timing issues generated by the slow processing of the Rasp PI).

=== release test-debugger-repl ===
Path: simple/test-debugger-repl
./node debug --port=13683 /home/pi/node0.8.6/test/fixtures/breakpoints.js
line> debug>< debugger listening on port 13683
line> debug>connecting... ok
line> debug>break in test/fixtures/breakpoints.js:1
line>  1 debugger;
line>  2 function a(x) {
line>  3   var i = 10;
line> debug>break in test/fixtures/breakpoints.js:11
Error: Timeout. Expected: /9/
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-debugger-repl.js
=== release test-force-repl ===
Path: simple/test-force-repl
timers.js:103
            if (!process.listeners('uncaughtException').length) throw e;
                                                                      ^
Error: timeout!
    at Object._onTimeout (/home/pi/node0.8.6/test/simple/test-force-repl.js:30:9)
    at Timer.list.ontimeout (timers.js:101:19)
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-force-repl.js
=== release test-debugger-repl-utf8 ===
Path: simple/test-debugger-repl-utf8
./node debug --port=13683 /home/pi/node0.8.6/test/fixtures/breakpoints_utf8.js
line> debug>< debugger listening on port 13683
line> debug>connecting... ok
dying badly
Error: Timeout. Expected: /break in .*:1/
Command: out/Release/node /home/pi/node0.8.6/test/simple/test-debugger-repl-utf8.js
@stolsma
Copy link
Author

stolsma commented Aug 29, 2012

@originalmind Oeps, TooTallNate removed his branch so I made my own and referenced it. The receipt above should work again now!!

With the other instructions (exporting variables etc) you get a not working SSL module or a partly working older Raspbian system shared SSL module that is not optimized for use with Node....

@natevw
Copy link

natevw commented Aug 30, 2012

Note that if you're setting this up on a rather fresh SD card (as installing git-core implies) you will need to first configure your git identity — otherwise the patches will not apply! I'd quickly pasted in the full "shell script" above without watching and so the build still failed.

@natevw
Copy link

natevw commented Aug 30, 2012

I can confirm this mostly works. Thanks @stolsma for this post!

It doesn't seem to fix the HTTPS protocol issue for me though:

var f = require('fermata');
f.raw({base:'https://xs4all.nl'}).get(function (e,d) { console.log(e,d); });
// Error: 1074672352:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:683:

Based on your comment I was under the impression this should work?

@chrisjenx
Copy link

Amazing, Worked perfectly!

@abulte
Copy link

abulte commented Sep 13, 2012

Worked perfectly here too, thanks !

@stolsma
Copy link
Author

stolsma commented Sep 14, 2012

@natevw That HTTPS problem you are seeing is probably related to the use of openssl 1.0.0f in node i.r.t. XS4ALL using 512 bit and higher stuff... They are busy implementing openssl 1.0.1c now in node master so maybe that helps ???

@stolsma
Copy link
Author

stolsma commented Sep 14, 2012

To all: Today the node team landed the two remaining patches on the 0.8.10pre branch! So it looks like that these instructions are not needed anymore when node 0.8.10 is released!!! Yippieajee!!!!!! :-)

I have also updated the patch locations to the node repository for everyone still trying to compile node <0.8.10

@leommoore
Copy link

Thanks Sander, that worked a treat on my pi

@shaunfreeman
Copy link

Thanks mate, worked first time. Nice post

@d0nd3r3k
Copy link

Install it in 5 min, no need to compile no more :)

wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz
tar xvzf node-v0.10.2-linux-arm-pi.tar.gz

you only need to add it to your path variables here:

nano /etc/profile

Check https://github.com/DonaldDerek/rPi-cheat-sheet for more info..

@antonywu
Copy link

@DonaldDerek, thanks!

I didn't have to add any path. I only had to symbolic link node and npm to be under /usr/bin
sudo ln -s ./node-v0.10.2-linux-arm-pi/bin/node /usr/bin/node sudo ln -s ./node-v0.10.2-linux-arm-pi/bin/npm /usr/bin/npm

@sgerrand
Copy link

sgerrand commented Jan 9, 2015

@DonaldDerek et al who come here in search of a ARM binary:

For whatever reason, there is no longer an ARM binary available on the node.js distribution site. 😾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment