How To Install MongoDB community edition on Ubuntu 20.04–22.04

Safaetul Ahasan
2 min readAug 8, 2022
  1. Import the public key used by the package management system.
wget -qO — | sudo apt-key add -

2. Create a list file for MongoDB.

echo “deb [ arch=amd64,arm64 ] focal/mongodb-org/6.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

3. Reload the local package database.

sudo apt-get update

4. Install the MongoDB packages

sudo apt-get install -y mongodb-org

5. Start MongoDB

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload
sudo systemctl start mongod

6. Verify that MongoDB has started successfully.

sudo systemctl status mongod

7. version check

mongod — version

8. To access MongoDB shell, run the command mongosh.

  1. To list existing databases
show dbs

3. To display the database you are using


4. To create/switch to a new database in MongoDB:

use blog

Error Solution of Ubuntu 22.04:

Ubuntu 22.04 doesn’t have official MongoDB packages yet, so the best option now is to have Ubuntu 20.04, where official MongoDB packages are available.

It’s NOT recommended to use any workaround in Ubuntu 22.04 to install MongoDB, because it can lead to problems if you gonna use it in production. Below is the workaround that worked for me:

  1. Download libssl1.1_1.1.1f-1ubuntu2_amd64.deb from the official repository:

2. Install it:

sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb

3. Proceed with the installation of MongoDB:

sudo apt-get install -y mongodb-org

This solution is from MongoDB Forum, but I also added a few notes to keep in mind.