How to Install MongoDB on Ubuntu 20.04

Install MongoDB on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure Install MongoDB on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

MongoDB is one of the most popular free and open-source NoSQL databases. MongoDB has written in C++ for massive scalability, high performance, and availability. It stores data in JSON-like documents and supports Ad hoc queries, indexing, and real-time aggregation.

Install MongoDB on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

Step 2. Install MongoDB on Ubuntu system.

Import the repository’s GPG key and add the MongoDB repository with:

After that the repository is enabled, install the MongoDB using the apt command:

Once the installation is completed, start the MongoDB daemon and enable it to start on boot by typing:

Confirm the version of the MongoDB server:

Step 3. Configuring MongoDB.

The MongoDB configuration file is named mongod.conf.

The authorization the option enables Role-Based Access Control (RBAC) that regulates users access to database resources and operations. If this option is disabled each user will have access to all databases and perform any action.

After editing the MongoDB configuration file, restart the mongod service for changes to take effect:

Step 4. Create Admin User

By default, MongoDB doesn’t authenticate users to read and modify data, and it is the biggest security concern. To enable authentication, first, create a database administrative user.

Step 5. Access MongoDB.

Connect to MongoDB shell by using the following command:

Congratulation, you have learned how to install and configure Install MongoDB on Ubuntu 20.04 LTS Focal Fossa. If you have any question, please leave a comment below.