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:
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:
As soon as the editor opens, copy the following text and save in the file as shown in the image:
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:
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:
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:
Start and Check Status of MongoDB
After the successful installation, we will start the MongoDB by using the systemctl command.
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:
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:
Enabling the MongoDB
We can enable the MongoDB by using the systemctl command as:
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
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.