Skip to content
Runbook

Install MongoDB on Fedora / RHEL

Document-oriented NoSQL database (BSON), designed for horizontal scalability and flexible schemas.

Databasenosqldocumentdatabasebson

Installation

Server (official repository) · dnf
sudo tee /etc/yum.repos.d/mongodb-org-8.0.repo > /dev/null <<'EOF'
[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
EOF
sudo dnf install -y mongodb-org

Targets RHEL 9 / Rocky / AlmaLinux 9. For 8 or 10, replace the 9 in baseurl with the matching RHEL major version.

Verify the installation

Verify
mongod --version

Service

Start
sudo systemctl start mongod
Stop
sudo systemctl stop mongod
Status
sudo systemctl status mongod
Restart
sudo systemctl restart mongod
On boot
sudo systemctl enable mongod

Important files

TypePathDescription
config/etc/mongod.confServer configuration (YAML).
data/var/lib/mongodbPath data directory (note: /var/lib/mongo, not /var/lib/mongodb).
log/var/log/mongodb/mongod.logServer log.

Default ports

27017

Command-line tools

  • mongoshAdministration and query shell.
  • mongodumpBinary export of a database.
  • mongorestoreRestores a binary dump.

Uninstall

Uninstall
sudo systemctl stop mongod
sudo dnf remove -y mongodb-org
sudo rm -r /var/lib/mongo /var/log/mongodb

Removing the directories permanently erases your data.

Good to know

  • Fedora is not an officially supported MongoDB platform: the repository is indexed only by RHEL major version (8/9/10), never by Fedora number. On native Fedora, prefer Docker.
  • SELinux is enabled by default: a custom dbPath may require an appropriate context.
  • Security: by default authentication is disabled and mongod listens only on 127.0.0.1. Never expose port 27017 before you have enabled `security.authorization` and restricted `net.bindIp` in /etc/mongod.conf.

Installation on RHEL / Rocky / AlmaLinux

We declare MongoDB's official YUM/DNF repository, then install the mongodb-org meta-package. Important point: the repository is indexed only by RHEL major version (8, 9, 10), which is why the baseurl above is hard-coded to 9 rather than $releasever — on Fedora, dnf would resolve $releasever to a Fedora number (40, 41, 42…) and the repository would return a 404 error. Adjust the 9 to your major version if you are on RHEL 8 or 10.

Native Fedora is not an officially supported MongoDB platform: if you work on Fedora, the simplest path is to use Docker (see the corresponding Docker page).

A notable peculiarity of the Red Hat family: the default data directory is /var/lib/mongo (and not /var/lib/mongodb as on Debian). Since SELinux is enabled, if you move dbPath, remember to apply the right context (semanage fcontext / restorecon).

Security

Out of the box, MongoDB starts without authentication and mongod listens only on 127.0.0.1. That is safe locally, but not enough as soon as the machine is reachable from the network. Never expose port 27017 until you have, in /etc/mongod.conf, enabled security.authorization (after creating an administrative user) and restricted net.bindIp to the interfaces you actually need. A MongoDB instance left open without authentication is routinely scanned and compromised within minutes.