Tutorial

How To Install MongoDB on Ubuntu 14.04

Published on June 15, 2015
How To Install MongoDB on Ubuntu 14.04
Not using Ubuntu 14.04?Choose a different version or distribution.
Ubuntu 14.04

Introduction

MongoDB is a free and open-source NoSQL document database used commonly in modern web applications. This tutorial will help you set up MongoDB on your server for a production application environment.

Note: MongoDB can be installed automatically on your Droplet by adding this script to its User Data when launching it. Check out this tutorial to learn more about Droplet User Data.

Prerequisites

To follow this tutorial, you will need:

Step 1 — Importing the Public Key

In this step, we will import the MongoDB GPG public key.

MongoDB is already included in Ubuntu package repositories, but the official MongoDB repository provides most up-to-date version and is the recommended way of installing the software. Ubuntu ensures the authenticity of software packages by verifying that they are signed with GPG keys, so we first have to import they key for the official MongoDB repository.

To do so, execute:

  1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

After successfully importing the key you will see:

Output
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Step 2 — Creating a List File

Next, we have to add the MongoDB repository details so APT will know where to download the packages from.

Issue the following command to create a list file for MongoDB.

  1. echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

After adding the repository details, we need to update the packages list.

  1. sudo apt-get update

Step 3 — Installing and Verifying MongoDB

Now we can install the MongoDB package itself.

  1. sudo apt-get install -y mongodb-org

This command will install several packages containing latest stable version of MongoDB along with helpful management tools for the MongoDB server.

After package installation MongoDB will be automatically started. You can check this by running the following command.

  1. service mongod status

If MongoDB is running, you’ll see an output like this (with a different process ID).

Output
mongod start/running, process 1611

You can also stop, start, and restart MongoDB using the service command (e.g. service mongod stop, service mongod start).

Conclusion

You can find more in-depth instructions regarding MongoDB installation and configuration in these DigitalOcean community articles.

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

Learn more about our products

About the authors
Default avatar

Software Engineer, CTO @Makimo

Creating bespoke software ◦ CTO & co-founder at Makimo. I’m a software enginner & a geek. I like making impossible things possible. And I need tea.


Default avatar

staff technical writer

hi! i write do.co/docs now, but i used to be the senior tech editor publishing tutorials here in the community.


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!

sorry, i am novice. Where i can found after all this my MongoDB? :) i mean, config and etc.

There is a typo in the paragraph before the Conclusion “server mongod start” should be “service …” And this command requires certain permissions so you’ll be using “sudo service …”

I can’t find the Vivid version in the mongo repo right now: http://repo.mongodb.org/apt/ubuntu/dists/ What other version should be used?

seems to be failing now… $ sudo apt-get install -y mongodb-org Reading package lists… Done Building dependency tree
Reading state information… Done E: Unable to locate package mongodb-org

According to the mongodb web site (see https://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-ubuntu/) the file list command for Ubuntu 14.04 should be

$ echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

instead of the one documented in the article. Using the above command will allow me to install mongodb-org whereas the one mentioned in the article gave me an E: Unable to locate package mongodb-org error.

I’m a beginner and was wondering if i could host my go app and mongo db on the same droplet. The mongod service might run in the localhost on some other port such as 27017.

The current version of mongodb is 3.2. You need to follow the instruction on this link to install the latest version

This article should be updated, after the MongoDB 3.2 release.

You can also stop, start, and restart MongoDB using the service command (e.g. service mongod stop, server mongod start).

server mongod start => service mongod start

If i not mistake.)

Step 3 issue solution: if you face this issue E: Unable to locate package mongodb-org. then use following instead of it. sudo apt-get install -y mongodb

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!

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.