I am Hack Sparrow
Captain of the Internets.

Install MongoDB on Ubuntu

How to install MongoDB on Ubuntu

Having a tough time trying to install MongoDB on Ubuntu? This post will show you how to get MongoDB running on your Ubuntu box. Instead of compiling from source, we will be installing MongoDB using apt-get. Compiling MongoDB is a pain in the ass with all its very specific dependencies, so I personally prefer installing the compiled binary.

There are two MongoDB packages available for you to choose from - mongodb and mongodb-10gen.

The difference between mongodb and mongodb-10gen is that mongodb is officially made available by Ubuntu, and mongodb-10gen is made available by 10gen, the creators of MongoDB. mongodb-10gen is the latest stable version of MongoDB and is often fresher than mongodb. I personally prefer mongodb-10gen.

In case you wanna install MongoDB from mongodb package, just do this:

$ sudo apt-get install mongodb

MongoDB is installed as a daemon, you can connect to it as soon as the installation is over using the mongo command.

$ mongo
MongoDB shell version: 2.0.1
connecting to: test

Note that mongodb and mongodb-10gen are conflicting packages. If you wanna install using mongodb-10gen, you should uninstall mongodb, if you have installed mongodb already.

$ sudo apt-get remove mongodb
$ sudo apt-get autoremove

Before you can install MongoDB from the mongodb-10gen package, you need to add 10gen's repository to /etc/apt/sources.list. The whole process goes like this:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
$ echo deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen | sudo tee -a /etc/apt/sources.list
$ sudo apt-get update

Once the repository is updated, you can install MongoDB from the mongodb-10gen package.

$ sudo apt-get install mongodb-10gen

Run the MongoDB client mongo to confirm everything is installed and working.

$ mongo
MongoDB shell version: 2.0.1
connecting to: test

And that's it. You successfully installed MongoDB on your Ubuntu system. According to 10gen, mongodb-10gen is still a work-in-progress, anytime you have any problem installing mongodb-10gen, you always install mongodb.

Make a Comment