MongoDB is a general purpose, document-based, distributed NoSQL Database built for modern applications and especially for the cloud era.

Unlike relational databases such as MySQL that store data within tables, MongoDB stores data in collections in BSON format, which is a binary serialization of JSON, stands for “Binary JSON”, anything you can do with JSON, you can do it with BSON as well, but with additional extensions that are not part of JSON, such as Date and BinData data types.

In this guide, you’ll learn how to install MongoDB on Ubuntu 20.04, make sure you have sudo privileges or root user.

First, importing the public key used by the package management system:

$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
OK

If you receive an error indicating that gnupg isn’t installed, make sure you install it using the following command:

$ sudo apt-get install gnupg

And then run the above command again to add the public key.

Second, we need to add the list file of MongoDB to our system, so each time when we apt update, we update MongoDB list files as well:

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

Now let’s refresh the local repository:

$ sudo apt update

Finally, let’s install the latest version of MongoDB:

$ sudo apt install -y mongodb-org

The -y flag will confirm that we’re agreeing for all required dependencies for MongoDB, this will take few seconds/minutes depending on your hardware.

Once installed, you can check the version of MongoDB you just installed:

$ mongod --version
db version v4.4.0
Build Info: {
    "version": "4.4.0",
    "gitVersion": "563487e100c4215e2dce98d0af2a6a5a2d67c5cf",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Conclusion

Awesome, in this tutorial, you managed to install MongoDB on your Ubuntu 20.04 machine. If you encountered any error installing MongoDB, I highly suggest you go read the official MongoDB documentation.

Happy Installing ♥