Recently I got a Raspberry Pi B+ and I couldn’t wait to start playing with it. My first project was a server application, which runs on NodeJS and uses MongoDB for storing data. This post will guide you how to setup a Pi with Node and Mongo as in my case, this was not that straightforward.
Before you Begin
Note that just doing “apt-get install nodejs” will not work on the Raspberry as the package is not compiled for ARM. Even if the package installs, if you try and run “node -v”, you’ll get an error saying something about segmentation – in this case, you should delete all node-related files read on 🙂
Obtaining the Proper Binaries
Luckily I managed to find a proper NodeJS binary, which was compiled for ARM. You can find binaries for the different NodeJS versions on node-arm. I just grabbed the latest:
wget https://node-arm.herokuapp.com/node_latest_armhf.deb sudo dpkg -i node_latest_armhf.deb
After this, you can do
to make sure everything is OK.
Getting MongoDB was a bit harder as there aren’t any (or at least I didn’t manage to find any) binaries for ARM uploaded. In this case, I had to build the binaries myself.
Use git to get Mongo’s source code from this GitHub repository, which is especially for ARM.
git clone https://github.com/skrabban/mongo-nonx86
To build the code, you will need the following dependencies:
sudo apt-get install scons build-essential libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libboost-all-dev
Next, compile the code!
IMRPORTANT: The compilation process on the Raspberry Pi takes a couple of hours. I started the compilation before going to bed. Also if you have a Pi with less than 512MB of RAM, it might not be enough for the compilation.
cd mongo-nonx86 scons sudo scons --prefix=/opt/mongo install
When these commands complete, you should have an installed MongoDB in the /opt/mongo directory.
NOTE: If you have trouble compiling the source, be sure to checkout the Building guidelines for the code. Also, I just got the latest version from the master branch, but if you need a nice and stable version with production quality, you might want to check the version branches (currently the latest version is v1.8).
These steps were taken from these two great blog posts: