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: //127.0.0.1: 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.