How to install MongoDB

There are different ways to install MongoDB on the different operating systems but I am showing only for ubuntu. There are two ways of installing MongoDB on Ubuntu systems.

1) Install MongoDB from apt repository

2) Install MongoDB from a downloaded.deb package

but I am representing through command base

Step 1:- Import MongoDB public GPG Key:

Before you can install any package from MongoDB apt repository, you need to download and import GPG key to your system.

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

Step 2:- Add MongoDB 4 APT Repository on Ubuntu 18.04 / Ubuntu 16.04

Ubuntu 18.04:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Ubuntu 16.04:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Step 3:- Install MongoDB 4 on Ubuntu 18.04 / Ubuntu 16.04

sudo apt update
sudo apt install -y mongodb-org

The service name is mongod now you can start the application by below command:

sudo systemctl enable --now mongod

Check Mongo status

sudo systemctl status mongod

Note:- If it is showing active (running) means MongoDB is running perfectly.