MongoDB logoI have successfully compiled MongoDB version 3.0.7 and tools on the Raspberry Pi 2.  Full instructions are after the break — click on “more“.  As usual I found great help from the Linux community for getting this to work on ARM7.  mongo, mongod, mongos, and tools are all working great.  The WiredTiger Engine does NOT work under 32-bit ARM but, AFAIK, all other components do 🙂

NOTE: I have made MongoDB 3.0.9 binaries available for Raspbian (Jesse) for R-Pi 2 – here.

 

Compiling MongoDB 3.0.7 under Raspbian Jessie on a Raspberry Pi 2:

NOTE: this take a few hours!  I’ve also heard reports that the compile may not have enough space on a “loaded” 16GB SD Card.  I used 2 different 32GB SD Cards with no issues.  You DO need a large swap file, however.

Do the usual bring-up-to-date:


sudo apt-get update
sudo apt-get upgrade

You will need a large swap file so as not to run out of memory during compile & link:


sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=824000
sudo mkswap /swapfile1
sudo chmod 0600 /swapfile1
sudo swapon /swapfile1

Load the appropriate tools and libraries required:


sudo apt-get install build-essential libssl-dev git scons libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev

create and go to the build directory & then clone the source repository:


cd
mkdir build_mongodb
cd build_mongodb/
git clone git://github.com/mongodb/mongo.git
cd mongo
git checkout r3.0.7

download the patched file, “SConscript” needed for ARM support in the V8-32.5 Javascript Engine.  You can get this file from GitHub at https://gist.github.com/kitsook OR from this site at SConscript.

On an R-Pi, you can run these commands but PLEASE do not share this link!


cd
wget https://andyfelong.com/wp-content/uploads/2015/12/SConscript

Assuming you now have the file, “SConscript” in your home directory — confirm it and move to the target directory:


cd
ls -l SConscript
cd ~/build_mongodb/mongo/src/third_party/v8-3.25/

confirm that you are in the right place and can see the old SConscript — then overwrite the old file with the patched version:


pwd
ls -l SConscript
mv ~/SConscript ./SConscript

OK, you are now ready to compile the core elements of MongoDB — mongod, mongo, and mongos. NOTE that I use the “-j 2” option (use 2 cores) NOT “-j 4” (use 4 cores) for compiling as I kept getting random errors with “-j 4”, ranging from “internal error” to “error 9”.   The “-j 2” option has worked reliably for me in a couple of trials.

[NOTE – 06 Apr 2016: corrected a typo in directory path, below]

cd ~/build_mongodb/mongo
scons -j 2 --ssl --wiredtiger=off --js-engine=v8-3.25 --c++11=off --disable-warnings-as-errors CXXFLAGS="-std=gnu++11" core

You can ignore the “Warning: swp{b}” messages as the R-Pi Jessie kernel supports the needed ARM instructions.  You can walk away from the compile for 2-3 hours 😉  If things go well, you will eventually see: “scons: done building targets.”.

Congratulations!  You will find non-stripped binary executables for mongod, mongo and mongos in the directory:  “~/build_mongodb/mongodb”.  You could setup your PATH variable to include this directory or continue as described below to get stripped binaries (smaller!) ready for “final” install.

Make sure you still have the large swap file.  FYI: the file will be disabled on a reboot.  Run the install script:


cd ~/build_mongodb/mongo
scons --ssl --wiredtiger=off --js-engine=v8-3.25 --c++11=off --disable-warnings-as-errors CXXFLAGS="-std=gnu++11" install

After about 15 minutes, you should see, “scons: done building targets.” — if things went well 😉   You will now have stripped binaries in  “~/build_mongodb/mongo/build/install/bin”


cd ~/build_mongodb/mongo/build/install/bin
ls -l

MORE TO COME on how to install, set the database directory and set other default MongoDB settings.  Also, I will document how to build the MongoDB Tools.  That build requires “Go” which also needs to be compiled 😉