[2 min installs] MongoDB on Ubuntu

Better Stack Team
Updated on August 30, 2022

Here is how to install MongoDB on Ubuntu 20.04 in under 2 minutes:

Step 1 - Import the public key used by the package management system

From a terminal, issue the following command to import the MongoDB public GPG Key from https://www.mongodb.org/static/pgp/server-5.0.asc:

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Copied!

Step 2 - Create a list file for MongoDB

Create the list file /etc/apt/sources.list.d/mongodb-org-5.0.list for your version of Ubuntu.

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
Copied!

Step 3 - Reload the local package database

Issue the following command to reload the local package database:

sudo apt-get update
Copied!

apt update downloads the package lists from the repositories and updates them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.

Step 4 - Install the MongoDB packages

To install the latest stable version, issue the following command:

sudo apt-get install -y mongodb-org
Copied!

That’s it

You have successfully installed MongoDB on your Ubuntu 20.04 system.

Check Uptime, Ping, Ports, SSL and more.
Get Slack, SMS and phone incident alerts.
Easy on-call duty scheduling.
Create free status page on your domain.
Got an article suggestion? Let us know
Next article
[2 min installs] MariaDB on Ubuntu
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.