FedoraRHEL Based

How To Install MongoDB on Fedora 41

Install MongoDB on Fedora 41

MongoDB has become a cornerstone in the world of database management systems, particularly for applications requiring high performance, scalability, and flexibility. As a NoSQL database, it stores data in a format that is more akin to JSON documents rather than traditional rows and columns. This makes it an excellent choice for developers looking to build modern applications. In this guide, we will walk through the process of installing MongoDB on Fedora 41, ensuring you have a solid foundation to leverage this powerful database system.

Understanding MongoDB

What is MongoDB?

MongoDB is an open-source NoSQL database designed for handling large volumes of data across distributed systems. Unlike traditional relational databases that utilize structured query language (SQL) for data manipulation, MongoDB uses a flexible schema that allows for dynamic data structures. This flexibility makes it easier to adapt to changing application requirements.

Use Cases for MongoDB

  • Big Data Applications: MongoDB excels in handling large datasets and provides powerful analytics capabilities.
  • Real-Time Analytics: Its ability to process high volumes of data quickly makes it ideal for real-time analytics applications.
  • Content Management Systems: The flexible schema allows for easy updates and changes to content structures.

Prerequisites for Installation

System Requirements

Before installing MongoDB on Fedora 41, ensure your system meets the following minimum hardware specifications:

  • RAM: At least 4 GB (8 GB or more is recommended for production environments).
  • Disk Space: Minimum of 10 GB available disk space.
  • Processor: A modern multi-core processor.

Software Requirements

You will need the following software packages installed on your Fedora system:

  • DNF Package Manager: This is typically pre-installed on Fedora systems.
  • Curl: For downloading files from the web.

User Permissions

A user with root or sudo privileges is required to install software packages on Fedora. If you are not logged in as root, ensure you have access to a user account with sudo rights.

Setting Up the MongoDB Repository

Step 1: Create the Repository File

The first step in installing MongoDB is to set up the repository configuration file. Open your terminal and execute the following command:

sudo nano /etc/yum.repos.d/mongodb-org.repo

Step 2: Add Repository Configuration

Add the following configuration to the repository file with the desired version number of MongoDB (e.g., `8.0`):

[mongodb-org-]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/8.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-8.0.asc

This configuration enables your system to fetch packages directly from the official MongoDB repository.

Step 3: Verify Repository Setup

You can verify that the repository has been added successfully by running:

sudo dnf repolist

This command will list all enabled repositories, including the one you just added for MongoDB.

Installing MongoDB on Fedora 41

Step 1: Update System Packages

Before proceeding with the installation, it’s good practice to update your system packages. Run the following command:

sudo dnf update

Step 2: Install MongoDB Packages

The next step is to install MongoDB Community Edition. Use this command:

sudo dnf install mongodb-org

This command installs the latest version of MongoDB along with its associated tools and libraries.

Step 3: Installing Specific Versions (Optional)

If you need specific components of MongoDB, you can install them individually using this command:

sudo dnf install mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools

This approach allows you to customize your installation based on your project’s requirements.

Configuring MongoDB

Step 1: Modify Configuration File

The default configuration file for MongoDB is located at `/etc/mongod.conf`. You may want to customize this file based on your needs. Open it with your preferred text editor:

sudo vi /etc/mongod.conf

Step 2: Basic Configuration Settings

You should verify or modify key settings in the configuration file, such as:

  • dbPath: The directory where MongoDB stores its data. The default is usually `/var/lib/mongo`.
  • logPath: The location where logs are stored, typically `/var/log/mongodb/mongod.log`.
  • bindIp: Configure this setting to allow connections from specific IP addresses; by default, it binds to localhost only.

Step 3: Configure Firewall Settings

If you have a firewall enabled on your Fedora system, you need to allow traffic through port 27017 (the default port for MongoDB). Execute the following commands:

sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent
sudo firewall-cmd --reload

Starting and Enabling MongoDB Service

Step 1: Start the MongoDB Service

You can start the MongoDB service using this command:

sudo systemctl start mongod

Step 2: Enable Service on Boot

If you want MongoDB to start automatically when your system boots up, run:

sudo systemctl enable mongod

Step 3: Check Service Status

You can verify whether the MongoDB service is running by executing:

sudo systemctl status mongod

This command will provide information about the service status and any potential errors that may have occurred during startup.

Verifying the Installation

Step 1: Connect to MongoDB Shell

The final step in confirming your installation is connecting to the MongoDB shell. Use this command:

mongo

Step 2: Run Basic Commands

You can run basic commands within the shell to check database status and version. For example, use:

> db.version()
> show dbs

This will display the current version of MongoDB and list any databases present on your server.

Troubleshooting Common Issues

  • If you encounter issues starting the service, check logs located at `/var/log/mongodb/mongod.log` for error messages.
  • If you cannot connect via `mongo`, ensure that your firewall settings are correct and that `mongod` is running.
  • If you receive permission errors, make sure that your user has sufficient privileges or try running commands with `sudo`.

Congratulations! You have successfully installed MongoDB. Thanks for using this tutorial for installing the MongoDB database on your Fedora 41 system. For additional Apache or useful information, we recommend you check the official MongoDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button