Easy to Install MongoDB on Ubuntu 20.04

MongoDB logo

Must read:

Ferdian Alfianto

Ferdian Alfianto

Ferdian Alfianto is an Internet enthusiast, Mac Lover; likes using Wordpress, experimenting with Linux (especially Debian and Ubuntu), tinkering with pfSense routers, happy experimenting with LEMP (Linux, Nginx, MariaDB, PHP) and Redis. You can contact me here.

This tutorial explains how to install and configure MongoDB Community Edition on Ubuntu 20.04.

MongoDB is a document database open-source and it's free. Belongs to a database family called NoSQL, which is different from traditional table-based SQL databases such as MySQL and PostgreSQL.

In MongoDB, data is stored in flexible documents such as JSON where field may vary from document to document. It does not require a predefined schema, and the data structure can change over time.

The standard Ubuntu repositories include an outdated version of MongoDB. Installing the latest MongoDB on Ubuntu is fairly straightforward. We will enable the MongoDB repository, import the repository's GPG key, and install the MongoDB server.

Installing MongoDB on Ubuntu 20.04

Perform the following steps as root or user with sudo privileges to install MongoDB on Ubuntu:

Install the dependencies needed to add the new repository over HTTPS:

sudo apt update sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

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

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - sudo add-apt-repository 'deb [arch = amd64] https://repo.mongodb.org/apt/ubuntu focal / mongodb-org / 4.4 multiverse'

At the time of writing this article, the latest version of MongoDB is version 4.4. To install another version, replace 4.4 with the version of your choice.

Once the repository is enabled, install the mongodb-org meta package by typing:

sudo apt install mongodb-org

Run and activate the MongoDB daemon so that it can run automatically when it boots, by typing the command:

sudo systemctl enable --now mongod

To verify whether the installation was successful, check by running the command:

mongo --eval 'db.runCommand ({connectionStatus: 1})'

The output will look something like below:

MongoDB shell version v4.4.0 connecting to: mongodb: // 27017 /? Compressors = disabled & gssapiServiceName = mongodb Implicit session: session {"id": UUID ("2af3ab0e-2197-4152-8bd0-e33efffe1464")} MongoDB server version: 4.4.0 {"authInfo": {"authenticatedUsers": [], "authenticatedUserRoles": []}, "ok": 1}

A value of 1 indicates a successful installation.


Latest articles:

MongoDB logo

Easy to Install MongoDB on Ubuntu 20.04

This tutorial explains how to install and configure MongoDB Community Edition on Ubuntu 20.04. MongoDB is a free, open-source document database. Belongs to the so-called database family

Related article:

rocket nginx

Rocket-Nginx + WP-Rocket: What are the Benefits?

What is Rocket-Nginx? Rocket-Nginx is a configuration add-on to Nginx for the WordPress cache plugin, WP-Rocket. The developer claims that by injecting the Rocket-Nginx configuration, the


The World's Cheapest Domain Hunt!

The cheapest domain, who doesn't love getting it? Yes, even the author of this blog loves to hunt for cheap domains :). Frequently questions are asked to the author,