How To Install MongoDB on Ubuntu Server

Monday, March 8, 2010

Initial user and directory setup

Before installing anything, I'm going to prepare some necessary
directories and create the mongodb user:

sudo adduser mongodb
# for the mongodb data files:
sudo mkdir /var/lib/mongodb
# for the log files:
sudo mkdir /var/log/mongodb
sudo chown mongodb /var/lib/mongodb/

Install dependencies

Install the needed dependencies for building MongoDB from source:

sudo apt-get -y install tcsh git-core scons g++
sudo apt-get -y install libpcre++-dev libboost-dev libreadline-dev xulrunner-1.9.1-dev

MongoDB uses SpiderMonkey for server-side Javascript execution. The
mongod project requires a file js.lib when linking. This page details
how to build js.lib.

curl -O
tar zxvf js-1.7.0.tar.gz
cd js/src
make -f Makefile.ref
sudo JS_DIST=/usr make -f Makefile.ref export

Build MongoDB

git clone git://
scons all
sudo scons --prefix=/usr/local/mongo install

Now, create the init.d script file to have MongoDB start up on a reboot.

sudo vim /etc/init.d/MongoDB
# my version of this script is here:
# make init script executable:
sudo chmod +x /etc/init.d/MongoDB
# set up runtime links:
sudo update-rc.d MongoDB defaults

And to get it up and running, just run the init script:

sudo /etc/init.d/MongoDB start

For http access, add 1000 to the port:


Here are some references that helped a lot in getting my own setup
- Quickstart
- Building for

- Building Spider

- Installing MongoDB on Ubuntu 9.04 Jaunty

Python Driver

  • install pymongo
  • API

This entry was tagged Linux and mongodb

comments powered by Disqus

© 2009-2013 All rights reserved. Powered by Pyramid

go to Top