How to Install MongoDB on Ubuntu 16.04

r00t August 6, 2017

Install MongoDB on Ubuntu 16.04

In this tutorial we’ll learn how to install MongoDB on Ubuntu 16.04. We will also install and configure its prerequisites. MongoDB is an open source, document database based on the cutting edge technology of NoSQL. It supports development of modern web applications, with features such as strong consistency, flexibility, expressive query languages and secondary indexes plus a lot more.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install MongoDB on Ubuntu 16.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y && apt-get upgrade -y

Step 2. Installing MongoDB on Ubuntu system.

First, add the official MongoDB repository:

apt-key adv --keyserver hkp:// --recv EA312927

After that, we now have to add a file containing the MongoDB repository details under our /etc/apt/sources.list.d/ from which package files will be fetched:

echo "deb "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

To start installing MongoDB from the repository we just added, we issue the command:

apt-get update
apt-get install -y mongodb-org

Step 3. Verifying MongoDB.

Once MongoDB has been installed, you will need to create system unit file, which determines how to start or stop the service, when should it be automatically started at boot:

nano /etc/systemd/system/mongodb.service

Paste the following text below:

Description=High-performance, schema-free document-oriented database

ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf


Once you have finishes, now you are ready to start the MongoDB service. Use the following commands to start the MongoDB server and enable it for starting at each boot time:

systemctl start mongod
systemctl enable mongod

Step 4. Connecting MongoDB Terminal.

Once the installation is done, you can connect to MongoDB terminal and execute the commands for the tasks you want to do:


Congratulation’s! You have successfully configured MongoDB on your Ubuntu 16.04 LTS server.


The Tags:

Leave a Comment

Comments are closed.