Installing mongodb on Raspberry Pi (using pre-compiled binaries)

By | February 6, 2014

For some time I have been struggling to install mongodb on Raspberry Pi v2 (512mb) by compiling it from source. This guide show you how to download, install and configure a pre-compiled version of mongodb.

I am using Raspbian Debian Wheesy:
Linux <hostname> 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux

At first I could not find any suitable pre-compiled binaries around and then tried several tutorials which involved to compile mongodb from source:
http://c-mobberley.com/wordpress/2013/10/14/raspberry-pi-mongodb-installation-the-working-guide/
and
http://mongopi.wordpress.com/2012/11/25/installation/

However no matter how I did it seemed that the poor Raspberry died or crashed each time I tried to compile the source without any useful errors or explanations. It simple just died. I tried to adjust my overclokcing settings, swap size, free up RAM etc. But still it did not want to work.

After days and hours of struggling with compling the sources I decided to give up and went to search for a pre-compiled version and found one that I got working:
https://github.com/brice-morin/ArduPi

Thank you Brice Morin!

Contents

Step-by-step guide

Update system

Run as root or with sudo:

apt-get update
apt-get upgrade

Download mongodb

I have put together a package with the binaries from Brice which you can download here or you can use git to fetch the files directly from his repository.
Download mongodb-rpi_20140207 binaries

Install and configure

Run as root or with sudo:

adduser --firstuid 100 --ingroup nogroup --shell /etc/false --disabled-password --gecos "" --no-create-home mongodb

cp -R mongodb-rpi/mongo /opt
chmod +x /opt/mongo/bin/*

mkdir /var/log/mongodb 
chown mongodb:nogroup /var/log/mongodb
mkdir /var/lib/mongodb
chown mongodb:nogroup /var/lib/mongodb

cp mongodb-rpi/debian/init.d /etc/init.d/mongod
cp mongodb-rpi/debian/mongodb.conf /etc/

ln -s /opt/mongo/bin/mongod /usr/bin/mongod
chmod u+x /etc/init.d/mongod

update-rc.d mongod defaults
/etc/init.d/mongod start

Browse to http://localhost:28017/ to see status of mongo db.

Mongod Status

Enjoy!

30 thoughts on “Installing mongodb on Raspberry Pi (using pre-compiled binaries)

  1. Duncan Jauncey

    Hi, thanks for posting these instructions – btw, there seem to be some newlines missing from the “install and configure” section which might confuse some people. 🙂

  2. andrea

    Thank you so much, but i have to add some tips for those who have my issues:

    * run every command as superuser, prepending sudo or typing commands in a root terminal;

    * the instructions
    $> mkdir /var/log/mongodb chown mongodb:nogroup /var/log/mongodb
    $> mkdir /var/lib/mongodb chown mongodb:nogroup /var/lib/mongodb
    are 4 different instructions:
    $> mkdir /var/log/mongodb
    $> chown mongodb:nogroup /var/log/mongodb
    $> mkdir /var/lib/mongodb
    $> chown mongodb:nogroup /var/lib/mongodb
    * same for the instruction:
    $> ln -s /opt/mongo/bin/mongod /usr/bin/mongod chmod u+x /etc/init.d/mongod
    need to be splitted in:
    $> ln -s /opt/mongo/bin/mongod /usr/bin/mongod
    $> chmod u+x /etc/init.d/mongod

    Thank you so much!

    1. admin Post author

      Thanks Andrea! I allready fixed the newlines as it were mentioned in previous comments. But apparently I missed some or made a few more new typos 🙂 Also added “Run as root or with sudo”.

  3. Gauthier

    Hi,

    Thanks for your build. I tried to create a shard. I have some segmentation faults…
    The mongodb version in 2.1.1-pre (non stable). Is there a particular reason to use a that ?

    The bug may be related to the 2.1.1-pre.

    thanks in advance

    1. admin Post author

      Hi Gauthier,

      Thanks for you comment. It is not my build. The original build that I provide is from: https://github.com/brice-morin/ArduPi

      I only provide instructions for howto download and install that build. So the only reason to use 2.1.1-pre would be that it is pre-compiled. I have not tried to do any sharding so I am not sure the problem is related to the 2.1.1-pre version of mongodb or the actual build itself. I guess the best option would be to try to install a stable version (either if you find a pre-compiled version that works or to build one from scratch yourself). Sorry for not having more information.

      1. Brice Morin

        Hi,

        Thanks for the nice ack to my ArduPi repo 🙂

        As for the Mongo version, I actually used those sources:
        https://github.com/skrabban/mongo-nonx86

        They have ported the Mongo source code to ARM (which I guess included some tedious work related to big/LITTLE endian, etc that are different from x86), and I “just” compiled it on the Raspberry Pi (well, it was kind of pain, but it finally worked).

        AFAIK, the 2.1.1-pre is the last version these guys have ported. The official support for ARM should eventually come, see: https://jira.mongodb.org/browse/SERVER-1811

        Best regards,

        Brice.

  4. Guillaume

    Hello,
    Thanks for the tutorial, howerver, i’ve got several questions :
    how do you manage to download the source files into the raspberry as it wont accept the git command (dunno if the link is broken but it seems so for me), and if so, in which folder do you unzip it ?

    Cheers

    Guillaume

  5. Jens Knaack

    Thanks for this.
    I don’t know why, but I had to run it as root. Prepending sudo didn’t work.

  6. Pingback: Info: Running MongoDB on a Raspberry Pi | Rob Seder

  7. pawel

    there are problems with Date object it has problems with getting Time ( .getTime()) or changing hour etc. everything fails with segmentation fault. (but there is no array modification and it hangs when just typing var d = new Date(); \ d.getTime() in shell.)

    1. Brice Morin

      You can try using a timestamp instead of a date:

      #include

      bson_append_long(b, “bt”, time(NULL));

      It is probably a bit less convenient (depending on your use case), but it should be possible to extract a proper date using another lib if you need to display the dates.

  8. Pingback: Install Raspian OS,Node,MongoDB to SD card | Shiny Bug

  9. Robert Whittle

    Hi,

    Thanks for this, I’m attempting to run a meteorJS bundle on my pi…. All seemed to go well with the mongo installation, but when I attempt to start the mongo shell it says command not found. Is there something else I need to do? The mongod server is up and running fine…

    Thanks again

    1. omid

      I fixed this problem like this:
      sudo nano /etc/login.defs

      Find 2 lines starting with ENV_SUBPATH and ENV_PATH and add your mongo addres at the end of PATH like this:
      :/opt/mongo/bin

      that’s it!
      I saved the file and restarted my pi. I don’t know was it needed or not.

  10. Pingback: Nodarium: Step 1: Setup | MH2

  11. Prabhat

    Hello everyone,I am a new bee on this Raspberry Pi I want to install mongodb on raspberry pi so that i can use it in my project work.
    I founded this Post as the best one of all thanks to the admin of the page!!
    My query is that where should we place the downloaded binaries on the raspberry pi ???
    Please if any one can help me in this & provide me some guidelines !!

  12. Prabhat

    pi@RaspberryPi1234 ~ $ sudo /etc/init.d/mongod start
    [FAIL] Starting database: mongodb failed!
    pi@RaspberryPi1234 ~ $

    Thanks foe the post but its not running on my raspberry pi

    ******Tried with all the commands*****

    sudo apt-get update

    sudo apt-get upgrade

    sudo adduser –firstuid 100 –ingroup nogroup –shell /etc/false –disabled-password –gecos “” –no-create-home mongodb

    sudo cp -R mongodb-rpi/mongo /opt

    sudo chmod +x /opt/mongo/bin/*

    sudo mkdir /var/log/mongodb

    sudo chown mongodb:nogroup /var/log/mongodb

    sudo mkdir /var/lib/mongodb

    sudo chown mongodb:nogroup /var/lib/mongodb

    sudo cp mongodb-rpi/debian/init.d /etc/init.d/mongod

    sudo cp mongodb-rpi/debian/mongodb.conf /etc/

    sudo ln -s /opt/mongo/bin/mongod /usr/bin/mongod

    sudo chmod u+x /etc/init.d/mongod

    sudo update-rc.d mongod defaults

    sudo /etc/init.d/mongod start

    here is my kernel version & info of my OS

    RASPBIAN
    Debian Wheezy
    Release date:2015-02-16
    Default login:pi / raspberry
    Kernel version:3.18

    Pls help me to sort out the problem!!!

    1. admin Post author

      Hi Prabhat

      Try the following:

      Check log files in:
      /var/log/mongodb/mongodb.log

      Might be that your db is corrupt? If this is the case do the following:

      sudo service mongod stop

      Check if mongodb is running:
      ps wuax | grep mongo

      If it still is running kill it:
      killall -15 mongod

      sudo rm /var/lib/mongodb/mongod.lock
      mongod –repair –dbpath /var/lib/mongodb
      sudo service mongod start

      //Jonas

  13. Pingback: Install mongodb version >3 raspberry pi 2 | Solutions for enthusiast and professional programmers

  14. Pingback: Server Side | zcabh35healthinformatics

  15. Pingback: 树莓派安装MongoDB-树莓派

  16. Kevin Wood

    DUDE!
    Freakin AWESOME!
    Thank you. . . it actually works as advertised!
    a few tweaks when installing (re-running some instructions line by line that even a boob to LINUX/PI can figure out.)

    Again, thanks. Wanted to see ‘if I could do it, and with your instructions, I could!

Leave a Reply