DEV Community

koushik chatterjee
koushik chatterjee

Posted on • Updated on

How to install mongodb community edition to ubuntu 22.04

Image description
Mongodb is a widely used document oriented NoSQL database management system. Mongodb uses json like format called BSON ( Bianary Json) and it stores data in a collection of documents rather than storing in a table. Mongodb is designed in that way, it can be scaled and performed in an optional lavel and that became a choice for many large scale applications.
Mongodb is used in many web and mobile applications and here are the steps to install mongodb in ubuntu system 22.04,

step 1 : Import the MongoDB public GPG key:

sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode

step 2 : Create a file for mongoDB

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
Enter fullscreen mode Exit fullscreen mode

step 3: Reload the package database

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Step 4: Install MongoDB Community Edition

sudo apt-get install -y mongodb-org
Enter fullscreen mode Exit fullscreen mode

Step 5: Start mongoDB

sudo systemctl start mongod
Enter fullscreen mode Exit fullscreen mode

you can also enable automatic start of mongoDB on boot by using this command

sudo systemctl enable mongod
Enter fullscreen mode Exit fullscreen mode

Troubleshoot : While you are going to start mongoDB you might see this message,

MongoDB Install Fails on Ubuntu 22.04 - Depends on libssl1.1 but it is not installable as Ubuntu 22.04 has upgraded libssl to 3 and does not propose libssl1.1. as MongoDb has no official build for ubuntu 22.04. To overcome this issue ubuntu 22.04 installed in your system need to force the installation of libssl1.1 by adding the ubuntu 20.04 source:

step 1:

echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list
Enter fullscreen mode Exit fullscreen mode

Sep 2: Now again run the same previosly used command to install mongodb,

sudo apt-get install -y mongodb-org
Enter fullscreen mode Exit fullscreen mode

now delete the focal-security list file you just created,

sudo rm /etc/apt/sources.list.d/focal-security.list
Enter fullscreen mode Exit fullscreen mode

Now you you can start mongoDB in your system using command,

sudo systemctl start mongod
Enter fullscreen mode Exit fullscreen mode

and it will start working fine in your sytem.

Top comments (0)