Discover the step-by-step guide to install MongoDB on Linux Server 9. Unlock the power of this leading NoSQL database management system and harness its capabilities for your projects effortlessly with our comprehensive tutorial.
Table of Contents
What is NoSQL Database?
A NoSQL (Not Only SQL) database is a type of database management system that provides a mechanism for storage and retrieval of data that is modeled in ways other than the tabular relations used in relational databases. NoSQL databases are designed to handle large volumes of unstructured, semi-structured, or structured data, making them ideal for use cases where flexibility, scalability, and performance are paramount. Unlike traditional relational databases, NoSQL databases typically do not require a fixed schema, allowing for more agile development and accommodating changing data requirements. They are commonly used in applications such as web and mobile applications, real-time analytics, and big data processing.

What is MongoDB Database Server?
MongoDB is a leading NoSQL database that revolutionizes data storage and retrieval. It employs a document-oriented model, allowing for flexible and dynamic schemas. Each record, or document, can store data in a JSON-like format, making it exceptionally adaptable to evolving data structures. This flexibility empowers developers to work with complex data sets, accelerating development cycles.
One of MongoDB’s key strengths is its scalability. It excels at handling large volumes of data and high transaction loads, making it a go-to choice for applications with extensive data requirements. Its distributed architecture enables seamless horizontal scaling across multiple nodes, ensuring robust performance under heavy workloads.
Furthermore, MongoDB boasts exceptional speed in data retrieval and querying. It leverages indexes, sharding, and a powerful query language to swiftly locate and manipulate data. This capability is crucial for real-time applications and analytics, providing users with rapid access to critical information.
Security is a paramount concern in modern databases, and MongoDB addresses this with advanced features. It supports authentication, authorization, and encryption, safeguarding data from unauthorized access or tampering. Additionally, role-based access control and auditing mechanisms grant administrators fine-grained control over user permissions.
Read Also: How to install MongoDB on CentOS 8
In conclusion, MongoDB stands as a versatile and high-performance NoSQL database, favored by developers for its flexibility, scalability, and speed. Its document-oriented approach and distributed architecture make it an ideal choice for applications dealing with diverse and voluminous data sets. With robust security features, MongoDB ensures that sensitive information remains protected. By embracing MongoDB, businesses can build powerful, efficient, and secure applications that thrive in today’s data-driven landscape.
If you’re serious about mastering modern databases, MongoDB – The Complete Developer’s Guide 2025 by Maximilian Schwarzmüller is a must-have course. It takes you from the basics of NoSQL to advanced MongoDB features with real-world projects, making it perfect for developers, data engineers, and aspiring full-stack professionals. With Maximilian’s clear teaching style, you’ll gain practical skills that are highly in demand in today’s job market. Don’t miss the chance to future-proof your career with MongoDB expertise—[enroll now] and start building scalable, high-performance applications! (Disclaimer: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no extra cost to you.)
Environment Specification
For this setup, we are using a lightweight Rocky Linux 9 virtual machine (VM) configured with a minimal installation profile to reduce resource overhead. The VM has been allocated the following specifications:
- CPU – 3.4 Ghz (2 cores)
- Memory – 4 GB
- Storage – 40 GB
- Operating System – Rocky Linux release 9.2 (Blue Onyx)
- Hostname – mongodb-01.centlinux.com
- IP Address – 192.168.18.83/24
For experimenting with NoSQL databases like MongoDB on Linux Server 9, having a reliable, low-cost hardware setup can significantly enhance your learning experience. A compact Mini PC or a lightweight laptop provides an ideal environment for running MongoDB locally, allowing you to test configurations and deployments without the need for a full-scale server.
Additionally, if you prefer a cloud-based solution with greater scalability and remote access, opting for a VPS such as Rose Hosting offers excellent performance and flexibility for Linux servers. Both options cater well to developers and enthusiasts looking to gain hands-on experience with Linux and NoSQL databases in a convenient and cost-effective way.
Disclaimer: This post contains affiliate links. If you make a purchase through these links, I may earn a small commission at no extra cost to you.
Apple 2024 MacBook Pro Laptop with M4 chip with 10‑core CPU and 10‑core GPU: Built for Apple Intelligence, 14.2-inch Liquid Retina XDR Display, 16GB Unified Memory, 512GB SSD Storage; Space Black
15% OffPrepare your Linux Server
Login to your Rocky Linux server as root user by using a ssh client.
Set a hostname and Local DNS resolution for your Linux machine.
hostnamectl set-hostname mongodb-01.centlinux.com
echo "192.168.18.83 mongodb-01 mongodb-01.centlinux.com" >> /etc/hostsAs per best practice, update software packages in your Linux operating system before installing MongoDB database server.
dnf update -ySometimes, the above command updates your Linux Kernel. If it happens then you should reboot your Linux OS before installing MongoDB software.
rebootAfter reboot, check the version of Linux OS and Kernel, that are being used in this installation guide.
cat /etc/os-release
uname -rOutput:
NAME="Rocky Linux"
VERSION="9.2 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
5.14.0-284.30.1.el9_2.x86_64
Read Also: How to install MERN Stack on Rocky Linux 9
Install MongoDB on Linux Server
To install MongoDB server on Linux, you need to add Official yum repository of MongoDB in Linux OS.
Create a repo file by using vim text editor.
vi /etc/yum.repos.d/mongodb-org-7.0.repoAdd following lines in this file.
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.ascSave and exit from vim text editor by using :wq command.
Build yum cache for newly added yum repository.
dnf makecacheOutput:
MongoDB Repository 7.0 kB/s | 14 kB 00:02
Rocky Linux 9 - BaseOS 1.7 kB/s | 4.1 kB 00:02
Rocky Linux 9 - AppStream 626 B/s | 4.5 kB 00:07
Rocky Linux 9 - Extras 1.9 kB/s | 2.9 kB 00:01
Metadata cache created.
Execute following dnf command to install MongoDB on Linux.
dnf install -y mongodb-orgAfter MongoDB installation, check the version of your NoSQL database server by executing following command.
mongod --versionOutput:
db version v7.0.2
Build Info: {
"version": "7.0.2",
"gitVersion": "02b3c655e1302209ef046da6ba3ef6749dd0b62a",
"openSSLVersion": "OpenSSL 3.0.7 1 Nov 2022",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "rhel90",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
Jodel Archiv
$0.00 (as of November 2, 2025 19:42 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Post Installation Configuration
Execute following command to delete the temporary file: mongodb-27017.sock
rm -f /tmp/mongodb-27017.sockEnable and start mongod service.
systemctl enable --now mongodCheck the status of mongod service for any possible errors.
systemctl status mongodOutput:
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: disabled)
Active: active (running) since Mon 2023-10-16 18:34:44 PKT; 1min 22s ago
Docs: https://docs.mongodb.org/manual
Main PID: 1707 (mongod)
Memory: 86.8M
CPU: 2.711s
CGroup: /system.slice/mongod.service
└─1707 /usr/bin/mongod -f /etc/mongod.conf
Oct 16 18:34:44 mongodb-01.centlinux.com systemd[1]: Started MongoDB Database Server.
Oct 16 18:34:44 mongodb-01.centlinux.com mongod[1707]: {"t":{"$date":"2023-10-16T13:34:44.539Z"},"s":"
MongoDB 7.0 requires Kernel parameter:vm.max_map_count set to a higher value. Therefore, execute following command to do this.
echo "vm.max_map_count=262144" >> /etc/sysctl.d/99-mongod.confYour NoSQL database also required to disable Transparent Hugepages. Therefore, edit GRUB configuration file by using vim text editor.
vi /etc/default/grubFind and edit GRUB_CMDLINE_LINUX variable.
GRUB_CMDLINE_LINUX="resume=/dev/mapper/rl-swap rd.lvm.lv=rl/root rd.lvm.lv=rl/swap transparent_hugepage=never"Regenerate grub.cfg file based on new settings.
grub2-mkconfig -o /boot/grub2/grub.cfgOutput:
Generating grub configuration file ...
Adding boot menu entry for UEFI Firmware Settings ...
done
Reboot your Linux OS to apply changes.
rebootRead Also: Install Firebird Database Server on CentOS 8
Secure your MongoDB Database Server
Execute mongosh (MongoDB Shell) to login to your NoSQL database server.
mongoshOutput:
Current Mongosh Log ID: 652d43352747d53396b68cdc
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.1
Using MongoDB: 7.0.2
Using Mongosh: 2.0.1
mongosh 2.0.2 is available for download: https://www.mongodb.com/try/download/shell
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2023-10-16T19:04:37.082+05:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------
test>
Create an admin user in MongoDB database and set a password for it.
test> use admin
switched to db admin
admin> db.createUser(
... {
... user: "mongouser",
... pwd: passwordPrompt(), // or cleartext password
... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
... }
... )
Enter password
**********{ ok: 1 }
admin> quitLogin to your NoSQL database server by using the newly created user.
mongosh -u mongouserOutput:
Enter password: **********
Current Mongosh Log ID: 652d44176a7b04cc4b2967b6
Connecting to: mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.1
Using MongoDB: 7.0.2
Using Mongosh: 2.0.1
mongosh 2.0.2 is available for download: https://www.mongodb.com/try/download/shell
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2023-10-16T19:08:53.218+05:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------
test> db
test
Important Directories at MongoDB in Linux Server
Where does MongoDB store data Linux?
Default Data Directory: /var/lib/mongo
How to check MongoDB logs in Linux?
Default Log Directory: /var/log/mongodb
Read also: How to install Robo 3T on CentOS 8
Video Tutorial
Frequently Asked Questions (FAQs)
1. How does MongoDB handle transactions across multiple shards?
MongoDB supports multi-document ACID transactions across shards using a two-phase commit protocol, ensuring consistency. However, long-running transactions may impact performance.
2. What is the role of the oplog in MongoDB replication?
The oplog (operations log) is a capped collection that records all write operations, allowing secondary nodes to replicate changes from the primary in a replica set.
3. When should you use a covered query in MongoDB?
A covered query uses an index to return all required fields without scanning documents, improving performance. Use it when querying only indexed fields with projection.
4. How does MongoDB handle schema validation in flexible schema environments?
MongoDB allows schema validation rules via JSON Schema, enforcing structure on inserts/updates while maintaining flexibility for non-validated documents.
5. What are MongoDB’s best practices for indexing time-series data?
Use compound indexes on time-based fields (e.g., timestamp + sensor_id) and leverage time-series collections (introduced in MongoDB 5.0) for optimized storage and queries.
Final Thoughts
As you conclude your journey to install MongoDB on Linux Server 9, you’ve equipped yourself with a powerful tool for managing your data efficiently. MongoDB’s flexibility, scalability, and performance make it a valuable asset for a wide range of applications, from small-scale projects to enterprise-level solutions. By following the steps outlined in this guide, you’ve laid the foundation for leveraging MongoDB’s capabilities to drive innovation and success in your projects. With MongoDB installed and ready to use, you’re poised to harness the full potential of this leading NoSQL database management system.
From setting up scalable AWS solutions to managing complex Linux environments, I’ve got you covered. Visit my Freelancer profile to get started.


Leave a Reply
Please log in to post a comment.