Learn how to install MongoDB on AlmaLinux 10 step by step in this updated 2025 tutorial. This guide covers secure setup, creating MongoDB users, assigning DB.
If we’re building high-performance applications that need fast, flexible, and scalable databases, MongoDB is a top choice. This NoSQL database engine stores data in JSON-like documents, making it ideal for modern web, mobile, and cloud-based solutions. In this guide, we’ll walk step by step through installing MongoDB on AlmaLinux 10, one of the most stable RHEL-based distributions, making it a great match for production environments.
Prerequisites
Before starting, make sure our new Ubuntu server is ready. The following components should be installed and configured:
- A AlmaLinux 10 installed dedicated server or KVM VPS.
- A root user or normal user with administrative privileges.
Install MongoDB on AlmaLinux 10 with Secure Setup, User Management & CRUD Operations [2025 Guide]
Step 1: Update AlmaLinux System
Before we begin any software installation, let’s make sure our system is up to date to avoid conflicts:
sudo dnf update -y
Keeping our system updated ensures compatibility with MongoDB’s latest packages and secures our system against vulnerabilities.
Step 2: Add the MongoDB Repository
As of writing, MongoDB isn’t included in the default AlmaLinux 10 repositories. We need to manually add the official MongoDB YUM repository.
Let’s create the repository file:
sudo nano /etc/yum.repos.d/mongodb-org.repo
Paste the following configuration for MongoDB 8.0 (latest stable as of June 2025):
[mongodb-org-8.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/8.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-8.0.asc
Save and close the file (CTRL+O, Enter, then CTRL+X if using nano).
Step 3: Install MongoDB on AlmaLinux 10
Now that the repository is set, we can install MongoDB using DNF:
sudo dnf install -y mongodb-org
This command installs:
- mongod – the MongoDB server daemon
- mongos – MongoDB sharding router
- mongo – the legacy client shell
- mongosh – the modern MongoDB shell
💡 Always install the latest stable version to benefit from performance improvements and security patches.
Step 4: Start and Enable MongoDB Service
Once installation is complete, we need to start the MongoDB service and ensure it auto-starts on system boot.
sudo systemctl start mongod
sudo systemctl enable mongod
To verify MongoDB is running:
sudo systemctl status mongod
Look for active (running) in green—this confirms everything is good.
Step 5: Allow MongoDB in Firewall (If Enabled)
If we’re running a firewall (which is default in most secure setups), we should allow MongoDB’s default port 27017
.
sudo firewall-cmd --permanent --add-port=27017/tcp
sudo firewall-cmd --reload
Step 6: Connect to MongoDB Shell
Let’s test our MongoDB setup using the new mongosh shell:
mongosh
You’ll enter the MongoDB prompt. From here, we can start creating databases and collections.
To exit the shell:
exit
Step 7: Optional – Secure MongoDB with Authentication
By default, MongoDB allows connections without authentication. For production, we must enable access control.
1. Create an admin user:
mongosh
Inside the shell:
use admin
db.createUser({
user: "admin",
pwd: "StrongPassword123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
})
exit
2. Enable authentication in the config file:
Edit the MongoDB config:
sudo nano /etc/mongod.conf
Under the security section, add:
security:
authorization: enabled
Then restart MongoDB:
sudo systemctl restart mongod
Now MongoDB is locked down, and all connections require authentication.
Step 8: Verify MongoDB is Enabled on Boot
To confirm MongoDB is set to run after reboots:
sudo systemctl is-enabled mongod
If it shows enabled, we’re all set.
Step 9: Create a MongoDB User and Assign a Database
Once MongoDB is installed and running, we can create custom users and assign them access to specific databases.
1. Start MongoDB Shell with Authentication
If authentication is enabled:
mongosh -u "admin" -p --authenticationDatabase "admin"
The -p
flag will prompt for the password securely.
2. Create a New User and Database
Let’s create a user appuser and assign them to a new database appdb with read-write access:
use appdb
db.createUser({
user: "appuser",
pwd: "AppUserPassword123",
roles: [ { role: "readWrite", db: "appdb" } ]
})
We just created:
- A new database called appdb (MongoDB auto-creates it on first use)
- A user named appuser with permissions to read/write data in appdb
To test this user:
mongosh -u "appuser" -p --authenticationDatabase "appdb"
Step 10: Perform CRUD Operations in MongoDB
Let’s learn how to perform Create, Read, Update, and Delete (CRUD) operations using the MongoDB shell.
A. Create – Insert a Document
use appdb
db.products.insertOne({
name: "Wireless Mouse",
price: 899,
stock: 50
})
This command creates a products collection and inserts a document.
B. Read – Query a Document
db.products.find({ name: "Wireless Mouse" })
To get all documents:
db.products.find()
C. Update – Modify an Existing Document
Let’s update the price of the product:
db.products.updateOne(
{ name: "Wireless Mouse" },
{ $set: { price: 799 } }
)
D. Delete – Remove a Document
db.products.deleteOne({ name: "Wireless Mouse" })
Step 11: List Databases, Collections, and Users
To see what we’ve created:
List all databases:
show dbs
Switch to a database:
use appdb
List collections in the current database:
show collections
List users in the current database:
db.getUsers()
Final Thoughts
With this step-by-step guide, we’ve not only installed MongoDB on AlmaLinux 10, but we’ve also learned how to:
Secure MongoDB with authentication
Create users with custom database access
Perform CRUD operations in a real-world app-like database
Whether we’re hosting web apps, analytics platforms, or internal tools, MongoDB gives us the speed and structure flexibility we need—and AlmaLinux provides the enterprise-grade stability to support it.
By ensuring firewall rules, service persistence, and authentication, we not only follow best practices but also prepare our systems for scalable, production-grade deployment.