How to Install MongoDB 6.0 in Ubuntu Inside AWS

You are currently viewing How to Install MongoDB 6.0 in Ubuntu Inside AWS

First, add the GPG key

wget -qO - | sudo apt-key add -

Next, we need to create a list file for MongoDB

echo "deb [ arch=amd64,arm64 ] focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Then, update the APT package list.

sudo apt-get update

Now it’s time to install MongoDB

sudo apt-get install -y mongodb-org

If you have typed everything correctly, then it should install MongoDB on your Ubuntu Machine.

Next, we need to start the MongoDB by running this command

sudo systemctl start mongod

Verify that it started, by running this command.

sudo systemctl status mongod

Next, we need to enable MongoDB when the system reboots, to do that, please run this command.

sudo systemctl enable mongod

Now, to run the mongo Shell and insert some data, please run this command


Modify the MongoDB configuration file (usually located at /etc/mongod.conf) to bind the MongoDB server to the IP address of the machine or to to listen on all available network interfaces.[this is optional only if you want to allow external access to your DB]

Once you have finished the login to Mongo Shell, then you can insert data into collections. First, switch to any database by running the following commands.

use erpdatabase

Then run this command to insert a row.

   { firstName : "Atiqur",
     lastName : "Rahman",
     username : "randomuser0298",
     age : 35 , 
     gender : "Male",     

So once you have inserted the data, then you can search that data using the find method.

     username: "randomuser0298"
).limit( 10 ) 

A complete step-by-step guide created which can be watched any time and practice on your own AWS Account.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply