How to Install MongoDB in Linux (Ubuntu 20.04)

How to Install MongoDB in Linux (Ubuntu 20.04)

Hello Friends,

So in last chapter we understood about MongoDb and it’s advantages , In today’s topic we will know that how you can install MongoDb in ubuntu 20.04

First you need to run below command  to import the public GPG key

curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

After running above command you might face below error

E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation

So you can run below command to add this package

apt-get update && apt-get install -y gnupg2

If you’d like to double check that the key was added correctly, you can do so with the following command:

apt-key list

Now Run below command

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

After that run below command

sudo apt update

Then run below command to install mongodb

sudo apt install mongodb-org

You Might face below issue

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.0) but it is not installable
 mongodb-org-server : Depends: libssl1.1 (>= 1.1.0) but it is not installable
 mongodb-org-shell : Depends: libssl1.1 (>= 1.1.0) but it is not installable
E: Unable to correct problems, you have held broken packages.

Then Run below commands

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

sudo apt-get update
sudo apt-get install libssl1.1

Now we need to enable service

sudo systemctl start mongod.service

sudo systemctl status mongod

sudo systemctl enable mongod

Now you can run command mongo to use mongodb

Leave a Reply
Your email address will not be published. *