Installing NodeJS on a QNAP NAS running Debian Wheezy
by Thomas Urban
Prerequisites
The following set of instructions has been tested on a QNAP NAS TS-220 running freshly installed Debian Wheezy according to this tutorial. It might apply to similar systems, too.
Installing Toolchain
Compiling NodeJS from source requires installation of some tools for actually compiling, usually called a tool chain. This is achieved with the following command as root:
apt-get install make g++ libtool
Fetching Source Code
Invoke these commands on command line of QNAP NAS:
cd
mkdir dev
cd dev
wget "http://nodejs.org/dist/v0.10.32/node-v0.10.32.tar.gz"
tar xzf node-v0.10.32.tar.gz
cd node-v0.10.32
You might need to update the URL used on invoking wget to more recent version of NodeJS. The related names of archive on invoking tar and name of folder entered in last command need to be updated accordingly then.
Preparing Source Code
The source code of contained Javascript engine V8 needs to be patched for properly compiling on ARMv5. This patch has been given here and requires to insert three lines in file deps/v8/src/arm/macro-assembler-arm.cc. Open this file using
nano deps/v8/src/arm/macro-assembler-arm.cc
and look for lines reading like this
// We always generate arm code, never thumb code, even if V8 is compiled to
// thumb, so we require inter-working support
#if defined(__thumb__) && !defined(USE_THUMB_INTERWORK)
#error "flag -mthumb-interwork missing"
#endif
// We do not support thumb inter-working with an arm architecture not supporting
// the blx instruction (below v5t). If you know what CPU you are compiling for
// you can use -march=armv7 or similar.
#if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS)
# error "For thumb inter-working we require an architecture which supports blx"
#endif
Adjust it to read like this:
// We always generate arm code, never thumb code, even if V8 is compiled to
// thumb, so we require inter-working support
#if defined(__thumb__) && !defined(USE_THUMB_INTERWORK)
#error "flag -mthumb-interwork missing"
#endif
#if !defined(CAN_USE_THUMB_INSTRUCTIONS)
# define CAN_USE_THUMB_INSTRUCTIONS 1
#endif
// We do not support thumb inter-working with an arm architecture not supporting
// the blx instruction (below v5t). If you know what CPU you are compiling for
// you can use -march=armv7 or similar.
#if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS)
# error "For thumb inter-working we require an architecture which supports blx"
#endif
This is achieved by inserting the inner preprocessor conditional defining CAN_USE_THUMB_INSTRUCTIONS if required.
Compiling
Start configuring and compiling source code using these commands:
./configure
make
The first command is used to customize compilation e.g. to choose different target folder for later installation. The second command is processing output of first one by compiling all source files into binaries. This is going to take a while (1-2 hours).
Finally you may install NodeJS by running as root
cd /home/your-non-root-user/dev/node-v0.10.32
make install
This will install node and npm in /usr/local/bin and all global modules in /usr/local/lib.
Testing
Try running node now, e.g. for displaying the version number:
node -v
This should give output
v0.10.32
or any newer version according to the URL used for fetching source code above.