Tutorial

How To Install MongoDB on Ubuntu 12.04

Published on June 5, 2012
How To Install MongoDB on Ubuntu 12.04
Not using Ubuntu 12.04?Choose a different version or distribution.
Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

Install MongoDB on Ubuntu 12.04

MongoDB is a document database used commonly in modern web applications. This tutorial should help you setup a virtual private server to use as a dedicated MongoDB server for a production application environment.

Step 1 -- Create a Droplet

This one's easy. Once you're done, go ahead and `ssh` in.

N.B. :: It is recommended that you configure `ssh` and `sudo` like this

Step 2 -- Create the Install Script

The MongoDB install process is simple enough to be completed with a Bash script. Copy the following into a new file named `mongo_install.bash` in your home directory:

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

Here's an explanation of each line in the script:

  • The `apt-key` call registers the public key of the custom 10gen MongoDB aptitude repository
  • A custom 10gen repository list file is created containing the location of the MongoDB binaries
  • Aptitude is updated so that new packages can be registered locally on the Droplet
  • Aptitude is told to install MongoDB

TIP: At any time, to change to your home directory, simply execute `cd`

Step 3 -- Run the Install Script

Execute the following from your home directory:

$ sudo bash ./mongo_install.bash

If everything is successful, you should see the output contain a PID of the newly started MongoDB process:

mongodb start/running, process 2368

Step 4 -- Check It Out

By default with this install method, MongoDB should start automatically when your Droplet is booted. This means that if you need to reboot your Droplet, MongoDB will start right back up.

To start learning about the running `mongod` process, run the following command:

$ ps aux | grep mongo

One line of the output should look like the following:

mongodb    569  0.4  6.4 627676 15936 ?        Ssl  22:54   0:02 /usr/bin/mongod --config /etc/mongodb.conf

We can see the...

  • User: `mongodb`
  • PID: `569`
  • Command: `/usr/bin/mongod --config /etc/mongodb.conf`
  • Config File: `/etc/mongodb.conf`

Resources

By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Every now and than it looks like mongodb stops running.

When I

sudo service mongod start

It starts again.

Is there a way to auto start or check and auto start mongodb?

I concur - it would save time to have the last comment appear first.

Thanks for this, but I just tried it and got v2.4.1 installed, not the latest.

The instructions from 10gen here work.

Looks like they changed the name of their package for the latest release.

If you are getting the following error when running the bash script:

“WARNING: The following packages cannot be authenticated!”

Then you simply need to modify the last two lines of the script to:

apt-get -y --force-yes update apt-get -y --force-yes install mongodb-10gen

Everything should work fine after that.

whoops, I got it. it must have been a typo or something like that.

I created the bash script, but upon running it I get the following error:

Package mongodb-10gen is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package ‘mongodb-10gen’ has no installation candidate

I then tried using ‘sudo apt-get install mongodb-org’ (with or without -y) but it didn’t work either (E: Unable to locate package mongodb-org).

Maybe the package mongodb-10gen has been obsoleted?

Great tutorial, step 3 seems to be superfluous on ubuntu 12 though. Got a

mongodb start/running, process 6315

after running

sudo apt-get -y install mongodb-10gen

Using Debian 3.2.41-2+deb7u2 x86_64 GNU/Linux I got following error.

… electing previously unselected package mongodb-10gen. (Reading database … 26311 files and directories currently installed.) Unpacking mongodb-10gen (from …/mongodb-10gen_2.4.7_amd64.deb) … Processing triggers for man-db … locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory Setting up mongodb-10gen (2.4.7) … Adding system user mongodb' (UID 105) ... Adding new user mongodb’ (UID 105) with group nogroup' ... Not creating home directory /home/mongodb’. Adding group mongodb' (GID 111) ... Done. Adding user mongodb’ to group `mongodb’ … Adding user mongodb to group mongodb Done. invoke-rc.d: unknown initscript, /etc/init.d/mongodb not found. dpkg: error processing mongodb-10gen (–configure): subprocess installed post-installation script returned error exit status 100 Errors were encountered while processing: mongodb-10gen E: Sub-process /usr/bin/dpkg returned an error code (1)

Any suggestion?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
October 16, 2013

@Asterix: My bad, the second half of the command got stripped out because of the filtering system.

Is it all fine now?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel