MongoDB (Linux)


 If you already have installed the mongodb and you remove it make sure your run this command :       First, remove any existing repository file for MongoDB.

    sudo rm /etc/apt/sources.list.d/mongodb*.list

Step 1 – Setup Apt Repository

First of all, import MongoDB public GPG key in your system by issuing the following command. This key ensures package consistency and authenticity.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
Lets add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb.list.
echo "deb http://repo.mongodb.org/apt/debian "$(lsb_release -sc)"/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb.list

Step 2 – Install MongoDB Server

After adding required APT repositories, use the following commands to install MongoDB on your systems. It will also install all dependent packages required for MongoDB.
sudo apt update
sudo apt install mongodb-org