In this tutorial, we’ll walk through the process of installing MongoDB on Amazon Linux 2023 without using Docker. MongoDB is a popular NoSQL database used for building modern applications, and Amazon Linux is a stable, secure, and high-performance environment. Installing MongoDB directly on the OS (as opposed to using Docker) can offer performance advantages and fewer layers to manage.
Let’s dive in!
Prerequisites
- An Amazon EC2 instance is running Amazon Linux 2023.
- Root or sudo access to the instance.
Step-by-step Installation Guide
1. Connect to Your Instance
Using SSH, connect to your Amazon EC2 instance.
ssh ec2-user@your-instance-ip-address
Update the System
Before installing any new software, it’s always a good idea to update the existing packages:
sudo yum update -y
Configure the MongoDB Repository
To install MongoDB, you’ll first need to create a .repo
file under /etc/yum.repos.d/
:
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
Note: This example uses the MongoDB 7.0 repository. You may want to check MongoDB’s official site for the latest version.
Install MongoDB
Now that you’ve set up the repository, you can install MongoDB:
sudo yum install -y mongodb-org
This command will install several packages, including:
mongodb-org-server: The MongoDB server itself.
mongodb-org-mongos: The MongoDB Shard service.
mongodb-org-shell: The MongoDB shell, is useful for administrative tasks.
mongodb-org-tools: Essential MongoDB tools.
Start MongoDB
With MongoDB installed, you can now start the service:
sudo systemctl start mongod
If you want MongoDB to start automatically at boot:
sudo systemctl enable mongod
Verify the Installation
Check the MongoDB service status:
sudo systemctl status mongod
You can also connect to your MongoDB server using the MongoDB shell:
mongosh
You should be greeted by the MongoDB shell prompt. If you see any error regarding OpenSSL, then run the below command to fix that.
sudo yum remove mongodb-mongosh
sudo yum install mongodb-mongosh-shared-openssl3
sudo yum install mongodb-mongosh
Conclusion
Congratulations! You’ve successfully installed MongoDB on Amazon Linux 2023 without using Docker. You can now proceed to configure and use your MongoDB instance for application development, testing, or production purposes. Remember to consult the official MongoDB documentation for best practices, especially when it comes to security and optimization.