How to Install MongoDB on AWS EC2 Ubuntu | 7 Steps To Go

Installing MongoDB on the Ubuntu EC2 instance in AWS is an excellent option if you plan on shifting to a NoSQL database. On top of the AWS benefits, you can expect efficient data management, on-demand scaling, and better security. 

Let’s see how the installation process works with a step-by-step approach.

How to Install MongoDB on AWS EC2 Ubuntu

How to Install MongoDB on AWS EC2?

Follow the steps below to install MongoDB on an AWS EC2 instance running Ubuntu.

1. Connect to Your EC2 Instance

Use SSH to connect to your EC2 instance. Modify the following command by replacing ‘your-instance-ip’ with the IP address of your EC2 instance. 

ssh -i your-key.pem Ubuntu@your-instance-ip

Also, replace the your-key.pem with the correct path to your private key file.

2. Update the Package List

Before you install MongoDB, the best practice is to update the existing package list.

sudo apt update

sudo apt upgrade -y

Add the MongoDB Repository

3. Add the MongoDB Repository

Use the command below to add the official repository of MongoDB to your system.

wget -qO – https://www.MongoDB.org/static/pgp/server-5.0.asc | sudo apt-key add –

echo “deb [ arch=amd64,arm64 ] https://repo.MongoDB.org/apt/Ubuntu $(lsb_release -cs)/MongoDB-org/5.0 multiverse” | sudo tee /etc/apt/sources.list.d/MongoDB-org-5.0.list

Install MongoDB

4. Install MongoDB

Use the package manager to install MongoDB on your Ubuntu system.

sudo apt update

sudo apt install MongoDB-org -y

install MongoDB on your Ubuntu system

5. Start MongoDB

You can now start the MongoDB service using this command.

sudo systemctl start mongod

6. Enable MongoDB to Start on Boot

If you want MongoDB to start automatically during system reboot, enable the service in the following manner.

sudo systemctl enable mongod

MongoDB to start automatically during system reboot

7. Verify that MongoDB is Running

Check the MongoDB status by executing the following command line.

sudo systemctl status mongod

Remember that this is a basic installation and setup guide of MongoDB on AWS EC2. And you might have to configure MongoDB further depending on your use case. For help, you can have a look at the MongoDB documentation.

Frequently Asked Questions and Answers

Can I run MongoDB on EC2?

You can install or deploy MongoDB on EC2 through the AWS marketplace. Get a deployment plan and configure the production node. Then, set up a storage space before having the MongoDB instance running.

Which EC2 instance is best for MongoDB?

The best EC2 instances for MongoDB are general-purpose instances because they offer the flexibility to upgrade memory and other resources. It can benefit starters who are yet to know their actual requirements.

Is MongoDB free on AWS?

The cost for MongoDB Atlas on AWS is somewhere between $9 to $60 per month. Generally, a shared instance will cost less than a dedicated one, and you only get charged for running instances.


MongoDB may allow arbitrary access by default, making it susceptible to security issues. Therefore, after you install MongoDB on AWS EC2, you should secure the MongoDB instance on your Ubuntu system. Doing so will require you to configure the MongoDB security settings, set up authentication, and use a firewall.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *