Databases

Install MongoDB on Fedora 45 / 44 and RHEL 10

MongoDB does not publish a Fedora repository, and Fedora ships no MongoDB server package, so any way to install MongoDB on Fedora borrows the RHEL build. The good news is that its RHEL 10 repository installs cleanly on Fedora 45 and Fedora 44, and mongod runs with SELinux left in enforcing mode. The one surprise is on Fedora 45, which moved to OpenSSL 4 while the RHEL binaries still link against libssl.so.3, so dnf pulls in the openssl3-libs compat package to close the gap.

Original content from computingforgeeks.com - post 4867

You’ll add the official repository, start the service, set a password and connect with mongosh locally and remotely. You’ll also fix the two SELinux traps people hit: a moved data directory on Fedora and an unconfined mongod on RHEL 10. We ran every step in November 2026 on Fedora 45, Fedora 44 and AlmaLinux 10.2 (our RHEL 10 stand-in), and got MongoDB 9.0.4 with mongosh 2.14.1.

Check which MongoDB build fits your system

Use the RHEL 10 repository on all three systems. MongoDB builds that repository for several series, from 7.0 and 8.0 up to 9.0, and the MongoDB release notes list 9.0 as the current stable release, so that is the one you’ll install here. What differs between the systems is the OpenSSL underneath and how SELinux treats the daemon, and those two things decide whether you have extra work to do.

SystemBase OpenSSLExtra package dnf addsmongod SELinux domain
Fedora 45openssl-libs 4.0.3openssl3-libs (compat)mongod_t, confined by the Fedora policy
Fedora 44openssl-libs 3.5.9Nonemongod_t, confined by the Fedora policy
AlmaLinux 10.2 / RHEL 10openssl-libs 3.5.8Noneunconfined_service_t until you load the MongoDB policy

Read the last column first. Fedora is the easier SELinux story, because its stock policy already ships the mongod_t domain and labels /var/lib/mongo and /var/log/mongodb for it. The RHEL 10 base policy does not, so on RHEL the daemon starts fine but runs unconfined, and you only notice if you go looking. Before you add anything, confirm the host clears these checks:

  • An x86_64 CPU from Intel Haswell or AMD Bulldozer onward, with AVX visible to the OS
  • A kernel outside 6.19 to 7.0.13, which mongod refuses to start on
  • SELinux in enforcing mode, the default on both Fedora and RHEL

On Proxmox or KVM, a kvm64 CPU type hides AVX from the guest, so set the VM CPU type to host. You can check all three in one line. The kernel matters most on Fedora, because a Fedora box that skipped updates for a few months can still sit in the blocked range:

grep -o -m1 ' avx ' /proc/cpuinfo; uname -r; getenforce

Our Fedora 45 box answered with the avx flag, kernel 7.2.15-300.fc45.x86_64 and Enforcing. Fedora 44 ran 7.2.13 and AlmaLinux 10.2 ran 6.12, so none of them sat in the blocked kernel range. If you are starting from a bare machine, our Fedora 45 server install guide gets you to this point.

Add the MongoDB repository

Create the repository file by hand rather than copying an old Fedora guide, because most of them put $releasever in the URL. On Fedora that variable expands to 45, and MongoDB has no redhat/45 tree, so dnf gets a 404 and you get no packages. Hardcode the 10 instead, which also means the file will not break when you upgrade Fedora.

sudo vim /etc/yum.repos.d/mongodb-org-9.0.repo

Paste the repository definition. Note that the signing key for the 9.0 series is server-9.asc, not server-9.0.asc.

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

The same file works unchanged on Fedora 45, Fedora 44 and RHEL 10, since all three pull from the el10 build. Fedora 45 now keeps the distro repo files in /usr/share/dnf5/repos.d and leaves /etc/yum.repos.d empty, but dnf5 still reads both directories, so a third-party file belongs in /etc/yum.repos.d where an upgrade won’t touch it.

Install MongoDB and mongosh

The mongodb-org metapackage brings everything you need in one transaction.

sudo dnf install -y mongodb-org

On Fedora 45 the transaction holds nine packages. The last one comes from the Fedora updates repository, not from MongoDB, and it is the OpenSSL 3 compat library the el10 binaries need.

Package                           Arch   Version        Repository           Size
Installing:
 mongodb-org                      x86_64 0:9.0.4-1.el10 mongodb-org-9.0   0.0   B
Installing dependencies:
 mongodb-database-tools           x86_64 0:100.20.1-1   mongodb-org-9.0 124.9 MiB
 mongodb-mongosh                  x86_64 0:2.14.1-1.el8 mongodb-org-9.0 278.7 MiB
 mongodb-org-database             x86_64 0:9.0.4-1.el10 mongodb-org-9.0   0.0   B
 mongodb-org-database-tools-extra x86_64 0:9.0.4-1.el10 mongodb-org-9.0  14.8 KiB
 mongodb-org-mongos               x86_64 0:9.0.4-1.el10 mongodb-org-9.0 211.1 MiB
 mongodb-org-server               x86_64 0:9.0.4-1.el10 mongodb-org-9.0 290.4 MiB
 mongodb-org-tools                x86_64 0:9.0.4-1.el10 mongodb-org-9.0   0.0   B
 openssl3-libs                    x86_64 1:3.5.9-1.fc45 updates           9.2 MiB

Transaction Summary:
 Installing:         9 packages

Total size of inbound packages is 207 MiB. Need to download 207 MiB.
After this operation, 914 MiB extra will be used (install 914 MiB, remove 0 B).

Read the transaction as a shopping list. You get the server and the mongos router, the mongosh shell and the database tools (mongodump, mongorestore and friends), and the whole set takes about 1 GB of disk before you store any data. On a first install dnf also asks to import the MongoDB 9 Release Signing Key with fingerprint B3B42B6C39E5CDDEC0A27E3CF366D55B602E502D; compare it before you accept. Fedora 44 and AlmaLinux 10.2 install eight packages, with no compat library, because their system OpenSSL is still the 3.x line. The terminal below shows the Fedora 45 run end to end, including the %post scriptlet that enables the unit:

dnf installing mongodb-org from the MongoDB RHEL 10 repository on Fedora 45, pulling openssl3-libs as a dependency

The compat package is not a hack you have to maintain. It is a regular Fedora 45 package, so dnf upgrade keeps it patched along with everything else, and rpm -q --requires mongodb-org-server shows the libssl.so.3 and libcrypto.so.3 dependencies that pull it in.

Start mongod with SELinux enforcing

The install scriptlet already created the multi-user.target symlink for mongod.service. Start the service now and keep it enabled for the next boot in the same command.

sudo systemctl enable --now mongod

Then check three things in one pass. You want the unit running, the process in the mongod_t SELinux domain, and the port open on localhost only.

systemctl status mongod --no-pager
ps -eZ | grep mongod
sudo ss -tlnp | grep 27017

A healthy Fedora 45 host shows active (running), the context system_u:system_r:mongod_t:s0 and a single listener on 127.0.0.1:27017. If ps shows unconfined_service_t instead, you’re on RHEL without the MongoDB policy, and the RHEL 10 section fixes that. If the unit fails within a second, check uname -r against the blocked kernel range before you dig any deeper. A fresh mongod used about 82 MB of RAM on our 3 GB VM, so it fits comfortably on a small lab box.

systemctl status mongod active, ps showing the mongod_t SELinux domain and port 27017 bound to localhost on Fedora 45

Two OpenSSL versions now live on the Fedora 45 host, so it’s worth knowing which one the server uses. The build info answers it.

mongod --version

The binary reports the el10 build and the compat library’s version:

db version v9.0.4
Build Info: {
    "version": "9.0.4",
    "gitVersion": "64ade602b836c9adeffba7fa038c887ffab56196",
    "openSSLVersion": "OpenSSL 3.5.9 29 Sep 2026",
    "modules": [],
    "allocator": "tcmalloc-google",
    "javascriptEngine": "mozjs-wasm",
    "environment": {
        "distmod": "rhel10",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

So the TLS stack inside MongoDB runs on OpenSSL 3.5.9 from openssl3-libs. Running ldd /usr/bin/mongod also lists libssl.so.4, which the Fedora libcurl drags into the same process. That mix caused no errors in our tests, but it is an untested combination as far as MongoDB is concerned, and it’s the reason we’d keep Fedora for development and RHEL 10 for production data.

Connect with mongosh

With no arguments, mongosh connects to 127.0.0.1:27017, so you don’t need a connection string on the server itself.

mongosh

Inside the shell, db.version() prints the server version and show dbs lists the three system databases a new install has. Read the banner above them, because it carries the startup warnings.

mongosh connected to MongoDB on Fedora 45 showing startup warnings, db.version and show dbs output

The first warning is the one you act on now. Access control is off, so anyone who can reach the port can read and write everything, and the next section fixes that. The other four are tuning advice, and /var/log/mongodb/mongod.log names the setting behind each one along with the value MongoDB wants:

  • Transparent huge pages enabled: always
  • Transparent huge pages defrag: defer+madvise (Fedora uses madvise)
  • khugepaged/max_ptes_none: 0 (Fedora uses 511)
  • vm.swappiness: 0 or 1 (Fedora uses 60)

Those are worth setting on a production box and harmless to ignore on a laptop, because they change memory behaviour for the whole host, not only for MongoDB. The MongoDB TCMalloc performance page explains the huge page values, and the production notes cover swappiness. The shell also sends usage telemetry by default, and you can turn that off with disableTelemetry() inside mongosh.

Once you are in the shell, our tested mongosh cheat sheet covers the commands you will reach for next.

Enable authentication

Create the admin user first, while access control is still off and mongosh can get in without credentials. Do it in mongosh, switched to the admin database, and let passwordPrompt() ask for the password so it never lands in your shell history.

use admin
db.createUser({ user: "admin", pwd: passwordPrompt(), roles: [ { role: "userAdminAnyDatabase", db: "admin" }, { role: "readWriteAnyDatabase", db: "admin" } ] })

mongosh prints Enter password, masks what you type and answers with { ok: 1 } once the user exists. The user means nothing yet, because the server still accepts anonymous clients. Type exit to leave the shell, then turn on enforcement in the server config.

sudo vim /etc/mongod.conf

Add this block at the end of the file. It is YAML, so the two-space indent matters.

security:
  authorization: enabled

Restart the service so it reads the change.

sudo systemctl restart mongod

Now prove both sides of the change. An anonymous query should fail, and a login that names the user and its authentication database should work.

mongosh --quiet --eval 'db.getSiblingDB("admin").getUsers()'
mongosh -u admin --authenticationDatabase admin

The anonymous call came back with MongoServerError: Command usersInfo requires authentication, which is the result you want. The authenticated session reported [ { user: 'admin', db: 'admin' } ] from connectionStatus, and a test insert into an inventory database read back correctly.

Unauthenticated mongosh call rejected, then admin login with authenticationDatabase admin and a test insert on Fedora 45

Those two roles cover users and data but not server monitoring, so commands such as db.serverStatus() will refuse this account. That is deliberate. Give each application its own user scoped to one database rather than sharing this one, so a leaked app password cannot read every other database on the server.

Confine mongod on RHEL 10

On RHEL 10 the install and start steps above are identical, and everything works, which is exactly why the gap is easy to miss. AlmaLinux 10.2 ran mongod as unconfined_service_t with its data directory labelled plain var_lib_t, because the RHEL base policy has no MongoDB module. SELinux reported zero denials, but it was not restricting the daemon at all, so a compromised mongod could touch anything the mongod user can. MongoDB maintains a fix in its mongodb-selinux repository, which you build from source. Its README still scopes the policy to RHEL 7 through 9, but it built, loaded and confined mongod on AlmaLinux 10.2 in our lab. Install the build tools first.

sudo dnf install -y git make checkpolicy policycoreutils selinux-policy-devel

Then clone the policy, build it and install it. The install target relabels the MongoDB paths for you, so there is no separate restorecon step.

git clone https://github.com/mongodb/mongodb-selinux
cd mongodb-selinux
make
sudo make install

Restart the daemon so it comes up in the new domain.

sudo systemctl restart mongod

After the restart the same AlmaLinux host showed the mongodb module loaded, mongod in mongod_t, and the data and log directories carrying mongod_var_lib_t and mongod_log_t. The policy has two limits. It only covers mongod, and the policy assumes the default port, dbPath, systemLog.path and pidFilePath, so keep all four at their defaults on RHEL. MongoDB also warns that with SELinux enforcing, operations that need server-side JavaScript can segfault, which matters if your application still relies on $where or mapReduce.

mongod running as unconfined_service_t on AlmaLinux 10 before the mongodb-selinux policy and as mongod_t after it

Skip this on Fedora. Its stock policy already defines mongod_t and labels the default paths, so there’s nothing for the module to add, and we didn’t load it on our Fedora hosts.

Move the data directory without an SELinux denial

Putting dbPath on a separate disk is common, and it’s where SELinux bites on Fedora. This section was tested on the stock Fedora policy only. On RHEL 10 with the MongoDB module loaded, a custom dbPath is outside what the mongodb-selinux policy assumes, and without the module the mongod_var_lib_t type doesn’t exist, so mount the new disk at /var/lib/mongo there instead. A directory you create under /data gets the generic default_t label, which mongod_t may not write. Our Fedora clones put the root filesystem on Btrfs, so a snapshot before you move data costs nothing; our guide to Btrfs Snapshots and Rollback with Snapper on Fedora 45 / 44 sets that up. Stop the service and copy the existing data, so your admin user and any test data come along.

sudo systemctl stop mongod
sudo mkdir -p /data/mongodb
sudo cp -a /var/lib/mongo/. /data/mongodb/
sudo chown -R mongod:mongod /data/mongodb

Point the server at the new path.

sudo vim /etc/mongod.conf

Change the dbPath line under storage and leave the rest alone.

storage:
  dbPath: /data/mongodb

This is the trap we hit. Because cp -a carries the SELinux labels along, mongod started fine on the new path. Nothing on the system says /data/mongodb should keep that label, though, and the first restorecon or full relabel flipped every file back to default_t. The next restart failed with an AVC denial on mongod.lock and this line in the MongoDB log.

"msg":"DBException in initAndListen, terminating","attr":{"error":"Location28596: Unable to determine status of lock file in the data directory /data/mongodb: boost::filesystem::status: Permission denied [system:13]: \"/data/mongodb/mongod.lock\""}

You’d expect a fresh copy to be safe, and that’s why this one hurts: the failure waits for the next relabel, which can be weeks later. The permanent fix is a file-context rule, so every future relabel gives the directory the MongoDB data type. Add it and apply it.

sudo semanage fcontext -a -t mongod_var_lib_t "/data/mongodb(/.*)?"
sudo restorecon -R /data/mongodb
sudo systemctl restart mongod

ls -dZ /data/mongodb now shows mongod_var_lib_t, the service comes back active, and the test document from the auth step was still there. The whole sequence, failure included, looked like this on Fedora 45:

AVC denial for mongod on a custom dbPath labelled default_t, fixed with semanage fcontext mongod_var_lib_t and restorecon on Fedora 45

If semanage is missing on your host, it lives in policycoreutils-python-utils. For reading other denials the same way, our SELinux survival guide for Fedora walks through ausearch and audit2why.

Allow remote connections through firewalld

Only open the port after authentication is on, because until then bindIp is the only thing keeping an open database off your network. Add the LAN address of the server next to localhost instead of binding to everything.

sudo vim /etc/mongod.conf

Edit the net section, and put the address of your own server in place of 10.0.1.50.

net:
  port: 27017
  bindIp: 127.0.0.1,10.0.1.50

Fedora Cloud images ship without firewalld, so install it if firewall-cmd is not found. firewalld already defines a mongodb service for port 27017. A rich rule lets you limit it to your own subnet instead of the whole internet.

sudo dnf install -y firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=10.0.1.0/24 service name=mongodb accept"
sudo firewall-cmd --reload
sudo systemctl restart mongod

SELinux needs no change for this, because port 27017 is already labelled mongod_port_t on Fedora and RHEL. ss should now show two listeners, one on localhost and one on the LAN address:

mongod.conf bindIp set to localhost and the LAN address, firewalld rich rule for the mongodb service and ss showing both listeners on Fedora 45

Test from a second machine. Our client was a Fedora 44 VM with the same repository file, and a box that only needs the shell can install mongodb-mongosh on its own. Put the user in the connection string and leave the password out, so mongosh prompts for it.

mongosh "mongodb://[email protected]:27017/?authSource=admin" --quiet --eval "printjson({ version: db.version(), user: db.runCommand({ connectionStatus: 1 }).authInfo.authenticatedUsers, dbs: db.adminCommand({ listDatabases: 1 }).databases.map(d => d.name) })"

The remote login authenticated as admin and listed the inventory database created on the server earlier, which proves the bind address, firewall rule and credentials all line up.

mongosh on Fedora 44 authenticating as admin to a remote MongoDB server and listing its databases

Anything beyond a trusted LAN needs TLS on top of this. Pair it with the host-level steps in our Fedora hardening guide before the port faces anything you don’t control.

Fix MongoDB errors on Fedora and RHEL 10

These are the errors from our runs, with the cause and the fix for each. The last one comes from MongoDB’s documentation rather than our lab, because none of our kernels fell in the affected range.

Status code: 404 for https://repo.mongodb.org/yum/redhat/45/mongodb-org/9.0/x86_64/repodata/repomd.xml

The repo file uses $releasever, which is 45 or 44 on Fedora, and MongoDB only builds RHEL trees 8, 9 and 10. Replace $releasever with a literal 10 as in the file above. Our guide to third-party repo 404s on Fedora covers the same failure for other vendors.

Status code: 404 for https://pgp.mongodb.com/server-9.0.asc

We hit this by guessing the key name from the older pattern. The 8.0 series key really is server-8.0.asc, but the 9.0 series key is server-9.asc. dnf downloads all 207 MiB of packages before it fails at the key. Fix the gpgkey line and rerun the install.

Unable to determine status of lock file in the data directory: Permission denied

A custom dbPath carries the wrong SELinux label. An empty new directory fails slightly earlier with Error creating journal directory and the same Permission denied [system:13]. Both clear with the semanage fcontext rule and restorecon from the data directory section. Never switch SELinux to permissive to get past it, because the next relabel brings the failure straight back.

MongoServerError: not authorized on admin to execute command { serverStatus: 1 }

The user authenticated, but its roles don’t include monitoring. Per the MongoDB docs on built-in roles, clusterMonitor grants read-only monitoring access, so grant it to the account that runs your monitoring tool, or create a dedicated monitoring user, rather than handing out root.

mongod exits at startup on kernels 6.19 to 7.0.13

MongoDB’s production notes say its bundled TCMalloc can crash on those kernels, so mongod detects them and refuses to start, whether it came from the repo, a tarball or a container. Update the kernel to 7.0.14 or later with sudo dnf upgrade kernel and reboot. Current Fedora 45 and Fedora 44 kernels are well past that range, so this mostly hits machines that haven’t been updated in a while.

MongoDB does not list Fedora as a supported platform, but the RHEL 10 repository is the route that works there. SELinux on Fedora confines MongoDB without help until you move its data, and RHEL 10 needs the MongoDB policy to get the same protection. If you’re choosing a database for a new project on the same box, our PostgreSQL on Fedora guide is the comparable install from Fedora’s own repositories, and our list of MongoDB books picks up where this setup ends.

Keep reading

How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Fedora How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Things to Do After Installing Fedora 45 Workstation Fedora Things to Do After Installing Fedora 45 Workstation Install NVIDIA Drivers on Fedora 45/44 (Secure Boot, Legacy GPUs) Fedora Install NVIDIA Drivers on Fedora 45/44 (Secure Boot, Legacy GPUs) Install Nix Package Manager on Fedora 45 / 44 with SELinux Fedora Install Nix Package Manager on Fedora 45 / 44 with SELinux Install PowerShell on Fedora 45 / 44: Use the RHEL 10 Repo Fedora Install PowerShell on Fedora 45 / 44: Use the RHEL 10 Repo Configure Custom PostgreSQL ports with SELinux Databases Configure Custom PostgreSQL ports with SELinux

4 thoughts on “Install MongoDB on Fedora 45 / 44 and RHEL 10”

Leave a Comment

Press ESC to close