Steps to install MongoDB server on Fedora Linux – Any version

This guide will help you install the latest or older versions of the MongoDB database server on Fedora 39/38/37/36 or any other version you are using.

MongoDB is a popular NoSQL database server that is available in community and enterprise editions. It is known for its high performance, flexibility, and scalability. It is a schema-less database, hence allowing developers to store even complex data types, which is the requirement of today’s modern applications.

Now, if you are using Fedora Linux and looking for commands to install MongoDB for your web applications, then the steps in this guide will surely help you out…

Prerequisites

Do we need any special settings to install MongoDB on Fedora Linux? Not at all, a few common things we need such as a user account with sudo rights and, an active internet connection, and the user who is following this guide must have basic knowledge of the command terminal.

Step 1: Configure the MongoDB Repository

Well, MongoDB is not available through the default Fedora Linux repositories, therefore we need to manually add a repo of the MongoDB version we want to install on our system.

For example- While doing this article, the latest version of the Database was 7.x, hence to add the repository for that we need to create a file:

Note: If you want to add another version such as 6. x, change 7.0 in the below commands with 6.0. Similarly, you can add the repository to install any other older or newer version of MongoDB.

Create a Repo file:

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

Copy-Paste the following code in it:

[mongodb-org]
name=MongoDB community Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc

Save the file by pressing Ctrl+O, hitting the Enter key, and then to exit, use the Ctrl+X keys.

Adding MOngoDB repository

Step 2: Update your package database:

After adding a new repository, our system must be aware of it and its packages. Therefore, run the given command:

sudo dnf makecache
Update your package database

Step 3: Install MongoDB on Fedora Linux

Finally, we have the MongoDB repository of the version we want to install on our Fedora Linux. Next, like as usual, use the DNF package manager to download and install the packages required for the installation of Mongo on Fedora.

sudo dnf install mongodb-org
Installing mongodb server Fedora

 

Step 3: Start and Enable MongoDB Service

After the installation is completed, you need to start the MongoDB service and enable it to launch at boot.

  • Start the MongoDB service:
sudo systemctl start mongod
  • Enable MongoDB to start on boot:bashCopy code
sudo systemctl enable mongod
  • Check the service status:
sudo systemctl status mongod --no-pager -l
  • To Stop MongoDB in the Future
sudo systemctl stop mongod

Uninstall MongoDB

You may not need MongoDB anymore on your Fedora Linux or just want to remove the current one to install some other, whatever the case, however, to uninstall MongoDB completely, here are the commands to follow:

  1. First, stop the MongoDB service
sudo systemctl stop mongod
  1. After stopping it, remove all the packages of MongoDB you have installed so far…
sudo dnf erase $(rpm -qa | grep mongodb-org)
Uninstall MongoDb fedora
  1. Also, remove the data directories to clean MongoDB and its log files, if not already…
sudo rm -r /var/log/mongodb /var/lib/mongo

 Other Articles:

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.