Install Node on The Raspberry Pi in 5minutes
Installing Node on a Raspberry PI used to be a whole lot of pain. Compiling an codebase that big on the Pi really taxes the system, plus the usual dependency challenges of native C code. Fortunately, the good chaps at nodejs.org have started automatically building Node for Linux arm Raspberry Pi. This makes life so much easier. Now we can install node in less that five minutes. Here’s how.
First, make sure you have the latest raspbian on your Pi. If you need to update it run.
sudo apt-get upgrade; sudo apt-get update;
Node and NPM
Now install Node itself
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 node-v0.10.2-linux-arm-pi/bin/node --version
You should see:
v0.10.2
Now set the NODE_JS_HOME variable to the directory where you un-tarred Node, and add the bin dir to your PATH using whatever system you prefer (bash profile script, command line vars, etc); In my .bash_profile I have:
NODE_JS_HOME=/home/pi/node-v0.10.2-linux-arm-pi PATH=$PATH:$NODE_JS_HOME/bin
Now you should be able to run node from any directory. NPM, the node package manager, comes bundled with Node now, so you already have it:
npm —version
prints
1.2.15
Native code
If you are just working with pure javascript modules then you are done. If you need to use or develop native modules then you need a compiler and node’s native build tool, node-gyp. The compilers should already be installed with Raspbian. Check using:
gcc —version
Install node-gyp with:
npm install -g node-gyp
Now any native module should be compilable.
That’s it. Node in 5 minutes.
Comments