Update 2: There's now an easier way to install Mongo on Raspbian:
apt install mongodb. This blog is kept for historical purposes now.
Update: @svvitale has made an install script that does all of this tutorial for you. So if you just need to quick get Mongo installed (which is fine, I probably would have done the same thing), that script is what you're looking for. If you really want to do it manually, read on.
I wanted to put this out there, because every other tutorial/blog I've seen for getting Mongo on a Pi requires you to build from a source, usually RickP's. However, doing that requires at least several hours, which I didn't feel like giving up. So, I did some digging around and found Mark Little's repo, which is a pre-compiled package of Mongo 2.1.1 (same as RickP's), which should be modern enough for most uses.
Installation is super simple, just uncompress the
mongo.tar.gz from the repo
and copy everything from
Next, make a new user for mongodb:
sudo adduser --firstuid 100 --ingroup nogroup --shell /etc/false --disabled-password --gecos "" --no-create-home mongodb
Then, create a folder for logs and state data:
sudo mkdir /var/log/mongodb/
sudo mkdir /var/lib/mongodb/
And set permissions on those folders:
sudo chown mongodb:nogroup /var/log/mongodb/
sudo chown mongodb:nogroup /var/lib/mongodb/
Then go to RickP's repo, and grab the
/debian/mongodb.conf files. Rename
and copy to
/etc/init.d/ on the Pi. Also copy the
mongodb.conf file to
Note: Some people have had trouble with carriage returns in the
mongodfile, so it might be a good idea to run
dos2unixon that file.
Finally, we need to
sudo chmod u+x /etc/init.d/mongod and
sudo update-rc.d mongod defaults to make our script executable on startup.
# Starting it up
You can now start MongoDB by executing
sudo /etc/init.d/mongod start or
sudo service mongod start. It should run like any other MongoDB installation
mongo from the terminal will open the interactive shell. If
you're looking for how to use mongo (because it is a little different than
traditional SQL syntax),
is a great starting point.
# Shutting it down
Note: Never pull the power cord from a Pi without first stopping Mongo.
If you do, the databases may become corrupted and you will have a hard time
fixing the mess you made. Before powering down the pi, quick run
sudo service mongod stop or
sudo /etc/init.d/mongod stop, and make sure it
is stopped before you shut down.
That's all you need to run Mongo on the Pi. Hopefully an enterprising person will come along and build a more recent version of Mongo for ARM devices. If that happens, I'll update this post accordingly, but for now, enjoy your MongoPi!
If you have any questions or if I made a mistake somewhere, please email me and let me know. You can also find this site on Github (see footer link) and submit a PR with your changes.
2014/09/19 - Added link to svvitale's script
2014/10/28 - Added how to start the mongo shell and link to documentation, thanks to Timo Denk.