How to Install MongoDB on Ubuntu 16.04/14.04 LTS

In this how to guide we shall go through the various steps of installing the latest version of MongoDB in Ubuntu 16.04 and Ubuntu 14.04 LTS systems. Read Also: How to Install MongoDB on...

Spread the love

In this how to guide we shall go through the various steps of installing the latest version of MongoDB in Ubuntu 16.04 and Ubuntu 14.04 LTS systems.

Read Also: How to Install MongoDB on Ubuntu 18.04

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.

Additionally, it offers organizations great scalability and performance for building modern applications with powerful and mission-critical databases.

Let us now proceed to how you can get it working on your Ubuntu 16.04 and Ubuntu 14.04 LTS systems by following these steps below:

Step 1: Adding MongoDB Repository

First, we are going to install the latest version of MongoDB, so we need to add the official MongoDB repository which has the latest package version:

$ sudo apt-key adv --keyserver hkp:// --recv EA312927
Add MongoDB Key

Add MongoDB Key

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.

Now run the following command as per your version of Ubuntu:

Ubuntu 16.04

$ sudo echo "deb xenial/mongodb-org/3.3 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.3.list

Ubuntu 14.04

$ sudo echo "deb trusty/mongodb-org/3.3 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.3.list

Ubuntu 12.04

$ sudo echo "deb precise/mongodb-org/3.3 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.3.list

Then save the file and close it.

Next, update the system package list as follows:

$ sudo apt-get update

Step 2: Installing MongoDB Database

Then install latest stable MongoDB package by executing the command below:

$ sudo apt-get install -y --allow-unauthenticated mongodb-org
Install MongoDB in Ubuntu 16.04

Install MongoDB in Ubuntu 16.04

In the command above, the option --allow-unauthenticated helps us to authentic the package that we are going to install without having to prompt us to confirm installation of a non-official Ubuntu repository package.

Now that MongoDB has been successfully installed on your system, there are certain important things we are going to do in order to manage it under systemd unit.

The first thing is to create a systemd unit file which defines a unit in this case our MongoDB service. Systemd unit configuration files are stored in /etc/systemd/system directory and we shall create the mongodb.service file under it, use your editor of choice as follows:

$ sudo vi /etc/systemd/system/mongodb.service 

Then add the following line into that file:


Description=High-performance, schema-free document-oriented database
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
Create SystemD MongoDB Service

Create SystemD MongoDB Service

A quick explanation of the file sections:

  1. Unit: contains a human readable description of the service and dependencies that need to be started for MongoDB service to work as required. The dependency here is the
  2. Service: specifies how the system should start a service depending on the directives provided. The User directive specifies user to run the MongoDB server and ExecStart directive specifies command to start MongoDB service.
  3. Install: Directs systemd to start the service at boot time when required.

There are many other directives that you can include in the unit file, you can find more by reading about systemd unit and here is a guide to start with: Create and Run New Service Units in SystemD.

At this point, we can now start our new service by running the command below:

$ sudo systemctl start mongodb

To check the status of the service, issue the following command:

$ sudo systemctl status mongodb
Start and Verify MongoDB Service

Start and Verify MongoDB Service

To make the services start at boot time, use the command below:

$ sudo systemctl enable mongodb

All is now set for you to start using MongoDB for developing databases for your applications.

If you are not familiar with how systemd works, then it is very important that you do some research to help you gain knowledge about it because, unlike other Linux init systems, it works in an absolutely different way.

I hope you find this guide useful, for any questions or additional information, you can use the comment section below to air out your concerns.

Facebook Comments

More Stuff

How to Install Let’s Encrypt SSL Certificate to Secure Apache on R... Extending the last Let’s Encrypt tutorial regarding SSL/TLS free certificates, in this article we are going to demonstrate how to obtain and install f...
EU to launch its own web domain By Chris Morris , BBC News : The European Commission has said that the new internet domain name ".eu" will be up and running by the end of 2005. The c...
Deal: Build a Web Developer Skill Set With the JavaScript Coding 2... JavaScript is a powerful scripting language that is used on the web to change HTML content. Today, JavaScript has become a key component of every web ...
This beautiful short Star Wars fan film brings Hamlet to a galaxy ... The works of William Shakespeare are incredibly versatile, especially when it comes to science fiction and fantasy. They’ve been translated into Kling...
Spread the love

Posted by News Monkey