Howto install Node.js on Arch linux (Raspberry Pi)

I was browsing the All Knowing and All Powerful ArchWiki and it surprised me to not to see any information in regards to installing node.js under Arch linux. Given that I consult this wiki for any matter involing linux (in general) I felt troubled. Then I remembered just how easy it is to install this:

*) From their GitHub page, they list a few prerequisites:

Prerequisites (Unix only):
GCC 4.2 or newer
Python 2.6 or 2.7
GNU Make 3.81 or newer

Gcc and Make can be installed via pacman:

1
2
3
4
5
6
7
8
9
10
11
12
[root@janusbox ~]# pacman -S gcc make
warning: gcc-4.7.2-4 is up to date -- reinstalling
warning: make-4.0-2 is up to date -- reinstalling
resolving dependencies...
looking for inter-conflicts...

Packages (2): gcc-4.7.2-4 make-4.0-2

Total Installed Size: 65.19 MiB
Net Upgrade Size: 0.00 MiB

:: Proceed with installation? [Y/n] Yes

If you don’t have python installed, you can install it using the same method above:

1
[root@janusbox ~]# pacman -S python2

In my case, python was installed but it was the wrong version:

1
2
3
4
[root@janusbox ~]# which python 
/usr/bin/python
[root@janusbox ~]# ll /usr/bin/python
lrwxrwxrwx 1 root root 7 Nov 29 11:22 /usr/bin/python -> python3

Since python2 was also installed, the symlink was updated to reflect the older version:

1
2
3
4
[root@janusbox ~]# unlink /usr/bin/python
[root@janusbox ~]# ln -s python2 /usr/bin/python
[root@janusbox ~]# python -V
Python 2.7.6

Once all the dependencies are installed, you can proceed with the node.js installation. I use a script named node.install. You can update the version accordingly (v0.10.11 or what ever is the latest):

node.installlink
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

mkdir -p /opt/src ; cd /opt/src/

git clone https://github.com/joyent/node.git

cd node ; git checkout v0.10.24

./configure ; make ; make install

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

This usually does not take that long to install, but coming from quad and dual core boxes, I was curious to see how long this would take to install on a Raspberry Pi:

Version: Raspberry Pi Model B
RAM: 512MB
CPU: ARMv6-compatible processor rev 7 (v6l)
Speed: 700 MHz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@janusbox ~]# time bash node.install 
Cloning into 'node'...
...
..
.
# .. left for a snack
# ... answered a call
# .... picked a movie
...
# Came back to this:
...
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
deps/v8/tools/gyp/v8_base.target.mk:225: recipe for target '/opt/src/node/out/Release/obj.target/v8_base/deps/v8/src/api.o' failed
make[1]: *** [/opt/src/node/out/Release/obj.target/v8_base/deps/v8/src/api.o] Error 4
make[1]: Leaving directory '/opt/src/node/out'
Makefile:38: recipe for target 'node' failed
make: *** [node] Error 2
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory '/opt/src/node/out'
g++ '-DENABLE_DEBUGGER_SUPPORT' '-DENABLE_EXTRA_CHECKS' '-DV8_TARGET_ARCH_ARM' '-DUSE_EABI_HARDFLOAT=1' '-DCAN_USE_VFP2_INSTRUCTIONS' -I../deps/v8/src -Wall -Wextra -Wno-unused-parameter -pthread -fno-strict-aliasing -mfloat-abi=hard -O2 -fno-strict-aliasing -fno-tree-vrp -fno-omit-frame-pointer -fno-rtti -fno-exceptions -MMD -MF /opt/src/node/out/Release/.deps//opt/src/node/out/Release/obj.target/v8_base/deps/v8/src/api.o.d.raw -c -o /opt/src/node/out/Release/obj.target/v8_base/deps/v8/src/api.o ../deps/v8/src/api.cc
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
deps/v8/tools/gyp/v8_base.target.mk:225: recipe for target '/opt/src/node/out/Release/obj.target/v8_base/deps/v8/src/api.o' failed
make[1]: *** [/opt/src/node/out/Release/obj.target/v8_base/deps/v8/src/api.o] Error 4
make[1]: Leaving directory '/opt/src/node/out'
Makefile:38: recipe for target 'node' failed
make: *** [node] Error 2
ln: failed to create symbolic link '/usr/bin/node': File exists

real 50m14.443s
user 41m14.780s
sys 4m5.210s
[root@janusbox ~]#

While the install script has never failed me on another system, it appears I would have to forsake it and do this manually. I have a feeling that this failed due to resource issues. “make“ picks up where it left off:

1
2
[root@janusbox ~]# cd /opt/src/node
[root@janusbox node]# time make

When it failed again, I took a look at the kernel logs and found something familiar:

1
2
Dec 20 17:22:42 janusbox kernel: [ 6933.155195] Out of memory: Kill process 16004 (cc1plus) score 196 or sacrifice child
Dec 20 17:22:42 janusbox kernel: [ 6933.164426] Killed process 16004 (cc1plus) total-vm:126576kB, anon-rss:101460kB, file-rss:5412kB

As I thought, there was simply not enough memory to handle this compilation task.

So it appears my options are to:

1) download the arm binary from elsewhere

2) spend the next few hours trying to figure this out, just so I can say I did it.

Given that I only have one real option, after trial and error, I cheated a bit and added a flash drive to act as swap space:

1
2
3
4
5
6
7
8
[root@janusbox ~]# mkswap /dev/sda1
mkswap: /dev/sda1: warning: wiping old ext4 signature.
Setting up swapspace version 1, size = 7817212 KiB
no label, UUID=757c3188-049a-4bb7-a34e-4df49d24d14f
[root@janusbox ~]# swapon /dev/sda1
[root@janusbox ~]# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda1 partition 7817212 0 -1

That worked quite well:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@janusbox ~]# time bash node.install 
...
..
.
# Took a nap
# Watched a movie
.
..
...
installing /usr/local/include/node/zconf.h
installing /usr/local/include/node/zlib.h

real 175m18.209s
user 149m3.540s
sys 6m36.570s
[root@janusbox ~]# node -v
v0.10.24
[root@janusbox ~]# npm -v
1.3.21

I win.