How to Install and Configure MongoDB on Ubuntu 20.04

Louis SanchezNovember 25th 2020, 7:11

Use this tutorial to install and configure MongoDB, which is a not only SQL (NoSQL) document storage server.

You will need access to a root account or an account with sudo privileges. To get the latest version of MongoDB, we need to add the MongoDB source to Ubuntu installation sources:

Step 1 : First, import the MongoDB GPG public key

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

Step 2 : Create a list file and add an install source to it

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

Step 4 : Update the apt repository sources and install the MongoDB server

sudo apt-get update
sudo apt-get install -y mongodb-org

Step 5 : You can start the mongod process by issuing the following command:

sudo systemctl start mongod

Step 5 : After installation completes, check the status of the MongoDB server

sudo service mongod status

Step 6 : Now you can start using the MongoDB server. To access the Mongo shell, use the following command

mongo

After installation, the MongoDB service should start automatically. You can check logs at /var/log/mongodb/mongod.log.