MongoDB is a freely accessible database. A database contains the gathered information at one place so it is easy to access, utilize and manage the stored data. Now if we go ahead, there are different types of databases for example a centralized database, cloud database, NoSQL database etc. all the databases are classified on the basis of properties. Instead of discussing all types we will have a short introduction of NoSQL databases because MongoDB belongs to it. NoSQL database means it can manage the data differently from the other conventional databases such as MySQL. MongoDB is a non-relational database, which can be used more conveniently. There are not a set of rules unlike other databases that you have to follow. You can manage data on a tabular form and can alter it at any time on the rules set by the user itself.

In this tutorial, we are going to discuss how MongoDB can be installed on Ubuntu 20.04. Let’s discuss the installation process in detail:

How MongoDB can be installed on Ubuntu

To install MongoDB on Ubuntu follow the below mentioned procedure:

Accessing the key of MongoDB

We will add the key of MongoDB from the official website of the MongoDB in the Ubuntu repository by using the command wget. It may ask for the permission of the administration by asking for a password so enter the password if required:

$ wget -qO – | sudo apt-key add

<img data-lazy- data-lazy-src="" data-lazy- height="176" src="data:image/svg xml,” width=”1287″>

As an output “OK” will be displayed which means the key has been added successfully in the repository of Ubuntu. After this, we will add the MongoDB repository in our source repository and for this purpose first we will open the sources list with the help of a nano editor:

$ sudo nano /etc/apt/sources.list

<img data-lazy- data-lazy-src="" data-lazy- height="130" src="data:image/svg xml,” width=”1283″>

As soon as the editor opens, copy the following text and save in the file as shown in the image:

deb [ arch=amd64,arm64 ] focal/mongodb-org/4.4 multiverse

<img data-lazy- data-lazy-src="" data-lazy- height="635" src="data:image/svg xml,” width=”1288″>

Exit the editor by saving the file by pressing CTRL S and then pressing CTRL X.

Updating and Upgrading Ubuntu Repository

After the downloading of the key of the MongoDB from its official website and addition of the MongoDB repository in the sources list of the Ubuntu repository we will update the repository of Ubuntu:

<img data-lazy- data-lazy-src="" data-lazy- height="259" src="data:image/svg xml,” width=”1283″>

We will also upgrade the repository so if there are any packages present which need to be upgraded, they can get upgraded at this point:

<img data-lazy- data-lazy-src="" data-lazy- height="249" src="data:image/svg xml,” width=”1281″>

The packages are updated as well as they are upgraded too.

Installation of MongoDB

For the installation of MongoDB, we will simply use the install command and will install the MongoDB as:

$ sudo apt install mongodb-org -y

<img data-lazy- data-lazy-src="" data-lazy- height="308" src="data:image/svg xml,” width=”1283″>

Start and Check Status of MongoDB

After the successful installation, we will start the MongoDB by using the systemctl command.

$ sudo systemctl start mongod

As there is no error, the command runs successfully and the MongoDB has been started, but to confirm the success of the above command we will check the status of the MongoDB:

$ sudo systemctl status mongod

<img data-lazy- data-lazy-src="" data-lazy- height="365" src="data:image/svg xml,” width=”1289″>

The active(running) status and green dot confirms the start command was run successfully and the MongoDB has been running.

Running the MongoDB

We can open the MongoDB by simply typing mongo:

<img data-lazy- data-lazy-src="" data-lazy- height="203" src="data:image/svg xml,” width=”1288″>

Enabling the MongoDB

We can enable the MongoDB by using the systemctl command as:

$ sudo systemctl enable mongod

<img data-lazy- data-lazy-src="" data-lazy- height="162" src="data:image/svg xml,” width=”1282″>

Testing of the MongoDB

For the testing of the MongoDB we will run a database diagnostic command by connecting to the server. We can do so by the following command

$ mongo –eval ‘db.runCommand({ connectionStatus: 1 })’

<img data-lazy- data-lazy-src="" data-lazy- height="394" src="data:image/svg xml,” width=”1285″>

The output shows that the MongoDB is not only installed properly but also working.


If you are in the beginning stages of web development, and you are developing the website then prefer to work on the MongoDB as it has no limitations for managing the data and you can manage your data easily by setting your own rules. MongoDB is nowadays being used mostly in web applications. In this tutorial, we have discussed the installation process of the MongoDB on Ubuntu 20.04.

About the author

<img alt="" data-lazy-src="" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Linux Explorer

Linux Explorer — Always exploring Linux and learning to advance the state of the art.