Install MongoDB on Ubuntu 16.04 [Tutorial Under 2 Minutes]

Install MongoDB on Ubuntu 16.04 [Tutorial Under 2 Minutes]


If you want to install MySQL on Ubuntu 16.04 server then, this article is for you. Before diving into the installation part, let us see a short introduction about MongoDB.

What is MongoDB?

MongoDB is No SQL Database management system unlike other relational database management system, MongoDB uses the Document structure in Jason Format to store the data instead of using Tables.

MongoDB started back then 2008 and has grown to a large extent due to it’s No SQL functionality.


  • If you have a new Ubuntu server create a sudo non root user or else just configure your system according to this Ubuntu 16.04 server setup guide.

Install MongoDB on Ubuntu 16.04

We can install MongoDB from ubuntu’s default repository or you can install Mongo DB from its Official repository for up to date version.

To install the MongoDB, we need the GPG Keys to verify the authenticity of the software. We have to add the official Repository to the Ubuntu server.

Also, let us first import the GPG keys for the repository. For that, use the below command.

You should get the following output, after importing the GPG keys.

After that, we will create a source file to indicate the location for apt to download the MongoDB.

After that, update the package index.

then, install the Mongo DB using the below command.

This command will run for sometime and install all the required components of the Latest MongoDB.


Start the MongoDB using the below command.

Then, check the status of MongoDB

You should get the following output

Whenever, we restart or start the system, the MongoDB also has to be started. For that, use the below command.

Now, it started running. If you want to stop mongoDB, please use the below command.

And then, when you want to start MongoDB, just use the start command we have used earlier in this article.

Configuring the Firewall for MongoDB

If you have followed our ubuntu initial server setup tutorial, you might not access the MongoDB from any external source.

You can only access it, by logging into the remote server. It is for security for purpose only. For small applications running on single server, it is fine and recommended.


if you hosted any other application on MongoDB and need to access remotely, then you have to enable the default MongoDB port 27017.

Use this simple command to accomplish the task.

if you enable the port, then you will be allowed to access MongoDB from internet from anywhere.

However, if you are only focused on connecting other applications or server to access the database, then specify the address of the source in the firewall.

Then, UFW will only allow connection to the MongoDB from the specified on the port.

For that, use the below command.

Now, Look at the UFW to find whether the changes have been reflected.

You will get the following output, if you have not specified any IP address during the process.

If you have specified any IP, then you should see the IP address instead of anywhere in the status.


Thats all. Now, you have installed Mongo DB on ubuntu 16.04 server. Your next step would be start coding and accessing the database.

Make sure, you subscribe for our upcoming free tutorial on cloud.

Leave a Reply

Your email address will not be published. Required fields are marked *