How to Install MongoDB on AWS EC2 Instance?
Last Updated :
02 Jan, 2022
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual computer on which we can perform all our tasks and we have the authority to configure, launch or even dissipate this virtual computer
In this article, we will learn how to install MongoDB on AWS EC2.
Prerequisite:
- AWS account.
- EC2 Instance.
- User with privileges to create Instance.
Implementation:
Follow the steps below to install MongoDB on AWS EC2 :
Step 1: Create an AWS Elastic Cloud Compute Instance.
Step 2: Start the EC2 instance that you have created in Step 1.
Step 3: Connect to your EC2 Instance by clicking on Connect Button.
Step 4: A prompt will pop up after connecting.
Step 5: At first check, if MongoDB is already installed or not.
mongod --version
Step 6: If MongoDB is not installed on your virtual machine then at first Install the public key using the following command.
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
Step 7: Add sources.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
Step 8: Reload the local package database using the following command.
sudo apt update
Step 9: Now install the MongoDB packages using the command.
sudo apt install -y mongodb-org
Step 10: Wait for the process to end.
Step 11: We have successfully installed MongoDB on our EC2 instance, to check if MongoDB is installed or not, verify using the following command.
mongod --version

MongoDB Commands:
sudo systemctl start mongod
- To Verify that MongoDB has started successfully:
sudo systemctl status mongod
sudo systemctl stop mongod
sudo systemctl restart mongod
MongoDB Commands
In this way, we can install MongoDB on our EC2 instance using EC2 Instance Connect. And if you also use a free tier account, make sure you delete all the resources you have used before logging out.
Similar Reads
How to Install MongoDB Compass on Linux? MongoDB is a free, open-source, cross-platform, document-oriented database. It is also classified as a non-SQL database program. Compass is an interactive tool for querying, optimizing & analyzing MongoDB data. It works in a visual environment. It can be installed in any operating system like Wi
1 min read
How to Install MongoDB on Alpine? MongoDB is an open-source NoSQL database. NoSQL databases are quite useful for working with large sets of distributed data. It is a good choice when your data is document-centric and doesn't fit well into the schema of a relational database. It provides full indexing support and replication with ric
2 min read
How to Install MongoDB on cPanel? cPanel is a web hosting management system. cPanel provides a control panel that provides a nice user interface. It is the most reliable site management system. Moreover, cPanel provides a dashboard where some web date files and MySQL files are present to help others out. MongoDB is a database and it
2 min read
How to Install Python3 on AWS EC2? AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
3 min read
How to Install R on AWS EC2? R is widely used as a different programming language. There are several programming languages are present for different purposes. The C programming language is used to get basic knowledge in the programming field. Java programming language is used to get some deep knowledge of programming & its
7 min read
How to Install MongoDB Enterprise on MacOS? In complement to SQL, MongoDB is a document database that is part of the NoSQL family of databases. Records in MongoDB are documents, which in JavaScript behave quite similarly to JSON objects. By using the field's key, values in documents can be sought. Because some fields/keys might be present in
2 min read