Install MongoDB on Ubuntu 18.04, 20.04, 22.04 & Debian

How to Install MongoDB on Ubuntu 18.04, 20.04, and 22.04 & Debian

MongoDB is a popular NoSQL database that is widely used for storing and managing large amounts of unstructured data. In this guide, we will show you how to install MongoDB on Ubuntu 18.04, 20.04, and 22.04.

Prerequisites

Before starting, you will need the following:

  • An Ubuntu 18.04, 20.04 and 22.04 or Debian Operatin System.
  • Root access to the system

Step 1: Add the MongoDB Repository

To install MongoDB, you will need to add the MongoDB repository to your system. You can do this by running the following command:

$ sudo apt-get install gnupg
$ wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

Then you should create a new sources list file for MongoDB:

Ubuntu 20.04:
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Ubuntu 18.04:
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Step 2: Install MongoDB

Now that the repository is added, you can install MongoDB by running the following command:

$ sudo apt-get update
$ sudo apt-get install -y mongodb-org

Step 3: Start MongoDB

After installation, you can start MongoDB by running the following command:

$ sudo systemctl start mongod

You can also enable MongoDB to start automatically on boot:

$ sudo systemctl enable mongod

Verify that MongoDB is running by checking its status:

$ sudo systemctl status mongod

Conclusion:

With the successful installation and running of MongoDB on your Ubuntu 18.04, 20.04, or 22.04 system, you can now proceed with creating and managing your databases and collections.

LEAVE A COMMENT