Guides 11792 Published by

This guide explains how to install MongoDB 5.0 on Debian 11 Bullseye by using the official repository so that package signatures stay intact and security patches are up‑to‑date. It walks you through adding a GPG key, creating the correct repo list entry, updating APT, and then installing the mongodb-org meta‑package before checking the server’s version. Once the service is started and enabled at boot, you can optionally edit /etc/mongod.conf to change bindIp for remote access and restart mongod to apply the new settings. Finally, it demonstrates a quick shell test and warns about potential conflicts when 4.x and 5.0 packages coexist.



Install MongoDB 5.0 on Debian 11 Bullseye

Want a fresh copy of MongoDB 5.0 running on your Debian 11 machine? This quick guide walks you through the exact steps and why each one matters, so you end up with a clean, up‑to‑date installation without the usual headaches.

Why the Official Repo Matters

Pulling from MongoDB’s own repository keeps the package signatures intact and ensures you get the latest security patches. If you grab a .deb off a random site, you risk a broken dependency chain or even malicious code.

1. Add the GPG key

   wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

Why? The key verifies that packages truly come from MongoDB, not some spoofing site.

2. Create the list file

   echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian bullseye/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Why? This tells APT where to look for MongoDB packages.

3. Update your package cache

   sudo apt-get update

Why? Keeps the local index fresh so you don’t end up installing an older or broken version.

Install the Core Packages

4. Pull in MongoDB 5.0

   sudo apt-get install -y mongodb-org

This pulls in `mongod`, `mongo`, and a few handy utilities all at once.

5. Check the version

   mongod --version

Why? Confirms you’re actually running 5.0, not some lingering 4.x.

Start the Service & Enable Autostart

6. Launch MongoDB

   sudo systemctl start mongod

7. Make sure it starts on boot

   sudo systemctl enable mongod

8. Verify the service status

   sudo systemctl status mongod

A quick sanity check to catch any misconfigurations before you start fiddling with data.

Tweak the Default Bind‑IP (Optional but Recommended)

By default MongoDB listens only on `127.0.0.1`. If you need remote access:

9. Edit the config

   sudo nano /etc/mongod.conf

10. Locate the bindIp line and change it to your server’s IP or 0.0.0.0 for all interfaces

    net:
      port: 27017
      bindIp: 127.0.0.1

11. Restart MongoDB

    sudo systemctl restart mongod

Why? Without this change, any client trying to connect from another machine will be denied.

Test the Connection

12. Run the shell

    mongo

13. Create a quick database

    use testdb
    db.test.insert({ hello: "world" })
    printjson(db.test.findOne())

If that prints `{ "_id": ObjectId("..."), "hello" : "world" }`, you’re good to go.

Common Pitfall: Conflicting MongoDB Versions

I’ve seen this happen after a bad driver update on systems with both 4.x and 5.0 installed side by side. `apt` sometimes pulls in the older `mongodb-org-server` package while leaving the newer client tools. Running `sudo apt-get install mongodb-org=5.0.*` forces a clean 5.0 stack.