Share on Social Media

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.

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.

Environment Specification

We are using a minimal Rocky Linux 9 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 4 GB
  • Storage – 40 GB
  • Operating System – Rocky Linux release 9.2 (Blue Onyx)
  • Hostname –
  • IP Address –

Recommended Training: Datawarehouse Linux NoSQL MongoDB – Job Interview Prep

4422594 a6dcshow?id=oLRJ54lcVEg&offerid=1074530.4422594&bids=1074530

Prepare 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
# echo " mongodb-01" >> /etc/hosts

As per best practice, update software packages in your Linux operating system before installing MongoDB database server.

# dnf update -y

Sometimes, the above command updates your Linux Kernel. If it happens then you should reboot your Linux OS before installing MongoDB software.

# reboot

After reboot, check the version of Linux OS and Kernel, that are being used in this installation guide.

# cat /etc/os-release
NAME="Rocky Linux"
VERSION="9.2 (Blue Onyx)"
ID_LIKE="rhel centos fedora"
PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"

# uname -r

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.repo

Add following lines in this file.

name=MongoDB Repository

Save and exit from vim text editor by using :wq command.

Build yum cache for newly added yum repository.

# dnf makecache
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-org

After MongoDB installation, check the version of your NoSQL database server by executing following command.

# mongod --version
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"

Post Installation Configuration

Execute following command to delete the temporary file: mongodb-27017.sock.

# rm -f /tmp/mongodb-27017.sock

Enable and start mongod service.

# systemctl enable --now mongod

Check the status of mongod service for any possible errors.

# systemctl status mongod
● 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
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 systemd[1]: Started MongoDB Database Server.
Oct 16 18:34:44 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.conf

Your NoSQL database also required to disable Transparent Hugepages. Therefore, edit GRUB configuration file by using vim text editor.

# vi /etc/default/grub

Find and edit GRUB_CMDLINE_LINUX variable.

GRUB_CMDLINE_LINUX="resume=/dev/mapper/rl-swap transparent_hugepage=never"

Regenerate grub.cfg file based on new settings.

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Adding boot menu entry for UEFI Firmware Settings ...

Reboot your Linux OS to apply changes.

# reboot

Secure your MongoDB Database Server

Execute mongosh (MongoDB Shell) to login to your NoSQL database server.

# mongosh
Current Mongosh Log ID: 652d43352747d53396b68cdc
Connecting to:          mongodb://
Using MongoDB:          7.0.2
Using Mongosh:          2.0.1
mongosh 2.0.2 is available for download:

For mongosh info see:

   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


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> quit

Login to your NoSQL database server by using the newly created user.

# mongosh -u mongouser
Enter password: **********
Current Mongosh Log ID: 652d44176a7b04cc4b2967b6
Connecting to:          mongodb://<credentials>@
Using MongoDB:          7.0.2
Using Mongosh:          2.0.1
mongosh 2.0.2 is available for download:

For mongosh info see:

   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

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

Video tutorial to install MongoDB on Linux Server

YouTube player

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.

Leave a Reply

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