How to Install MongoDB on Ubuntu 24.04 and 22.04

Last updated Wednesday, March 25, 2026 7:08 am 10 min read

Ubuntu’s older mongodb packages are not the right base when you need a current MongoDB document database server, because they can conflict with the upstream mongodb-org packages and leave you off the supported release track. To install MongoDB on Ubuntu with the official Community Edition packages, use MongoDB’s own APT repository so the server, mongosh, and the database tools stay on the same update path.

MongoDB 8.2 is the current stable release, and the upstream Ubuntu repository currently supports Ubuntu 24.04 and 22.04 for that branch. MongoDB 8.0 remains available on the same two releases, 7.0 is limited to Ubuntu 22.04, and Ubuntu 26.04 still lacks a native upstream repo, so the normal Community Server workflow stops at 24.04 and 22.04 instead of pointing Ubuntu 26.04 at an older suite.

Install MongoDB on Ubuntu

MongoDB’s own repository is the maintained path here. The Ubuntu mongodb package is not maintained by MongoDB Inc., and the official docs warn that it conflicts with mongodb-org if both are installed.

Compare MongoDB Community Server Branches on Ubuntu

The current branch picture is easier to follow when you separate MongoDB’s release naming from Ubuntu’s LTS matrix.

MongoDB BranchMongoDB StatusUbuntu SupportBest Fit
MongoDB 8.2Current stable releaseUbuntu 24.04 and 22.04New deployments that want the latest upstream Community Server
MongoDB 8.0Current major releaseUbuntu 24.04 and 22.04Stacks pinned to the 8.0 release line
MongoDB 7.0Previous stable releaseUbuntu 22.04 onlyOlder deployments that are not ready to move off 7.0 yet

MongoDB’s official docs still mention Ubuntu 20.04 for some branches, but LinuxCapable’s supported Ubuntu scope begins at 22.04. The repository workflow here stays inside that current support window.

LinuxCapable covers Ubuntu 24.04 and 22.04 for this topic. MongoDB’s native resolute repository paths for 8.2, 8.0, and 7.0 currently return 404, so Ubuntu 26.04 is not part of the standard upstream method yet.

Update Ubuntu Before MongoDB Installation

Refresh package metadata and apply any pending upgrades before you add another repository. The -y flag accepts APT’s confirmation prompt automatically.

sudo apt update && sudo apt upgrade -y

These commands use sudo for tasks that need root privileges. If your account does not have sudo access yet, run the commands as root or add a new user to sudoers on Ubuntu first.

Install Required Packages for the MongoDB Repository on Ubuntu

Install the packages that fetch and verify the repository metadata. Desktop systems often already have some of them, but cloud and minimal Ubuntu images usually do not. The flags in the curl command keep the download quiet and fail fast, and the curl command in Linux guide has broader examples if you want to go deeper.

sudo apt install -y ca-certificates curl gnupg

Import the MongoDB GPG Key on Ubuntu

MongoDB 8.2 currently uses MongoDB’s 8.0 release signing key for the Ubuntu repository. Import that key into a dedicated APT keyring before you add the source.

curl -fsSL https://pgp.mongodb.com/server-8.0.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/mongodb-server-8.0.gpg

The gpg --dearmor --yes step converts the ASCII-armored key into APT’s binary format and lets the command overwrite the keyring cleanly if you rerun it later.

Add the MongoDB 8.2 Repository on Ubuntu

Create the repository file with Ubuntu’s detected codename instead of hardcoding separate commands for 24.04 and 22.04.

. /etc/os-release
printf '%s\n' "deb [ arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu $VERSION_CODENAME/mongodb-org/8.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.2.list > /dev/null

The VERSION_CODENAME variable resolves to noble on Ubuntu 24.04 and jammy on Ubuntu 22.04. The dpkg --print-architecture part keeps the repo line aligned with your system architecture, and tee writes the file with root privileges because a plain > redirection would still run in your current shell.

cat /etc/apt/sources.list.d/mongodb-org-8.2.list
deb [ arch=amd64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2 multiverse

On Ubuntu 22.04, the same file uses jammy instead of noble. The rest of the line stays the same.

Refresh APT and Verify the MongoDB Package Source on Ubuntu

Refresh APT first, then confirm that mongodb-org is coming from MongoDB’s repository before you install anything.

sudo apt update

Relevant output includes:

Get:5 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2 InRelease [3,005 B]
Get:6 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages [22.9 kB]
apt-cache policy mongodb-org
mongodb-org:
  Installed: (none)
  Candidate: 8.2.6
  Version table:
     8.2.6 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages
     8.2.5 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages
     8.2.4 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages
     8.2.3 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages
     8.2.2 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages
     8.2.1 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages
     8.2.0 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages

On Ubuntu 22.04, the candidate version stays on the same 8.2.x track but the source path changes to jammy/mongodb-org/8.2.

Install MongoDB Community Edition on Ubuntu

Install the MongoDB metapackage once APT sees the right candidate. This pulls in the server, mongosh, and the supported database tools together.

sudo apt install -y mongodb-org

Start and Enable MongoDB on Ubuntu

Reload systemd once after installation, then enable MongoDB to start now and on future boots. The reload is harmless when it is not needed, and it avoids the occasional Unit mongod.service not found problem right after package installation.

sudo systemctl daemon-reload
sudo systemctl enable --now mongod

Verify MongoDB Versions on Ubuntu

Check both the server and the shell after installation. MongoDB Server and mongosh use separate version numbers, so do not expect them to match exactly.

mongod --version

Relevant output includes:

db version v8.2.6
Build Info: {
mongosh --version
2.8.1
mongosh --eval 'db.runCommand({ ping: 1 })'

This confirms that the local shell can reach the running server instead of only proving that the binary exists.

{ ok: 1 }

Ubuntu 22.04 validated with the same MongoDB 8.2.6 server branch and the same mongosh 2.8.1 release during testing.

Verify the MongoDB Service on Ubuntu

Confirm that systemd sees mongod as active, then verify that the server is listening on its default local port.

sudo systemctl status mongod --no-pager -l

Relevant output includes:

● mongod.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: enabled)
     Active: active (running) since Tue 2026-03-24 13:53:51 AWST; 592ms ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 8985 (mongod)
     Memory: 86.7M (peak: 86.7M)
        CPU: 221ms
     CGroup: /system.slice/mongod.service
sudo ss -lntp | grep 27017
LISTEN 0      4096       127.0.0.1:27017      0.0.0.0:*    users:(("mongod",pid=11650,fd=9))

Update MongoDB on Ubuntu

When you want newer MongoDB 8.2 patch releases from the same upstream repository, upgrade the metapackage instead of doing a full generic system upgrade first.

sudo apt update
sudo apt install --only-upgrade mongodb-org -y

Relevant output includes:

mongodb-org is already the newest version (8.2.6).
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.

If MongoDB publishes a newer 8.2.x build, the same command upgrades the installed packages from the repository you already configured.

Secure Your First MongoDB Deployment on Ubuntu

A fresh MongoDB install is fine for local testing, but the first real deployment should add an admin user and then turn on authorization before any remote clients come into the picture. This hardening flow was validated on Ubuntu 24.04 and 22.04 with the same MongoDB 8.2 packages.

Create the First MongoDB Admin User on Ubuntu

Create the first administrative account while the server still accepts local unauthenticated setup work. Replace StrongPasswordHere with a real password before you run the command block.

mongosh
use admin

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

exit

This account is enough to create other users and manage the server during the first setup pass. For long-term production use, you can later replace the broad readWriteAnyDatabase role with narrower per-database accounts for each application.

Enable MongoDB Authorization on Ubuntu

Open /etc/mongod.conf and make sure it contains one active security block with authorization enabled.

security:
   authorization: enabled

If the file already has a security section, edit that existing block instead of adding a duplicate. MongoDB only needs one active security key in the YAML file.

sudo systemctl restart mongod

Verify Authenticated MongoDB Admin Access on Ubuntu

Reconnect with the admin account you just created and verify that MongoDB accepts the authenticated admin command before you test the unauthenticated case.

mongosh -u admin -p --authenticationDatabase admin --eval "db.adminCommand({ listDatabases: 1 }).ok"

Relevant output includes:

1

Now confirm that a local connection without credentials is blocked.

mongosh --eval "db.adminCommand({ listDatabases: 1 })"

Relevant output includes:

MongoServerError: Command listDatabases requires authentication

Review MongoDB Network Access on Ubuntu

MongoDB installs with bindIp limited to 127.0.0.1 by default. That is the safest setting for single-host applications, local development, and any system where clients do not need to connect over the network.

Change MongoDB bindIp on Ubuntu for Trusted Networks Only

If another host really needs to reach MongoDB, edit /etc/mongod.conf so the net section includes a specific trusted address instead of exposing the server everywhere.

net:
  port: 27017
  bindIp: 127.0.0.1,192.168.1.10

Replace 192.168.1.10 with the server’s real private address. Avoid 0.0.0.0 unless you are deliberately exposing MongoDB behind tighter network controls and authentication.

sudo systemctl restart mongod

If you use UFW on the host, restrict port 27017 to trusted clients only. If UFW is not set up yet, install and configure UFW on Ubuntu first. Before you bind MongoDB beyond localhost, also review MongoDB’s security checklist and enable authentication for anything outside local testing.

Troubleshoot MongoDB on Ubuntu

Most Ubuntu install failures come down to one of three issues: the repository file points at the wrong release, the signing key is missing, or older Ubuntu MongoDB packages are already installed.

Fix Unable to Locate Package mongodb-org on Ubuntu

When APT cannot find mongodb-org, start by checking the source file you wrote earlier. It must match your Ubuntu codename exactly.

cat /etc/apt/sources.list.d/mongodb-org-8.2.list
deb [ arch=amd64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2 multiverse

On Ubuntu 22.04, the same line should use jammy instead of noble. If the file is wrong or missing, recreate it, run sudo apt update again, and recheck apt-cache policy mongodb-org.

Fix MongoDB Public Key Errors on Ubuntu

If apt update reports NO_PUBKEY 4B7C549A058F8B6B, reimport the MongoDB signing key and refresh APT. The 8.2 Ubuntu repo currently expects the 8.0 release key.

curl -fsSL https://pgp.mongodb.com/server-8.0.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/mongodb-server-8.0.gpg
sudo apt update

Fix MongoDB Package Conflicts on Ubuntu

If an older Ubuntu MongoDB package is already installed, it can block mongodb-org by trying to own the same binaries. Check what is already on the system first.

dpkg -l | grep -E 'mongodb|mongo-tools'

If that output includes Ubuntu packages such as mongodb, mongodb-server, or mongodb-server-core, remove those older Ubuntu packages before you retry the official install.

Remove MongoDB from Ubuntu

Removing MongoDB cleanly means stopping the service, purging the packages, and then deciding whether you want to keep or delete the data directory. The data removal step is destructive, so skip it if you still need the databases.

Stop MongoDB and Purge the Packages on Ubuntu

Stop the service first so package removal does not leave a running process behind.

sudo systemctl stop mongod
sudo systemctl disable mongod
sudo apt purge -y 'mongodb-org*' mongodb-mongosh mongodb-database-tools mongodb-org-database-tools-extra

Verify the MongoDB Packages Are Gone on Ubuntu

Check the package state before you remove the repository file. At this point, the repo can still exist, but the installed package should be gone.

apt-cache policy mongodb-org
mongodb-org:
  Installed: (none)
  Candidate: 8.2.6
  Version table:
     8.2.6 500
        500 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.2/multiverse amd64 Packages

The Installed: (none) line confirms the package is gone. The candidate remains until you remove the MongoDB repository itself.

Remove MongoDB Data and Repository Files on Ubuntu

Delete the repository file and keyring, then remove the MongoDB data and log directories only if you are sure you do not need the databases anymore.

sudo rm -f /etc/apt/sources.list.d/mongodb-org-8.2.list /usr/share/keyrings/mongodb-server-8.0.gpg
sudo rm -rf /var/lib/mongodb /var/log/mongodb
sudo apt update

Once the source file is gone and APT has refreshed, check whether the repository is still visible.

test ! -e /etc/apt/sources.list.d/mongodb-org-8.2.list && echo "MongoDB repository file removed"
MongoDB repository file removed
apt-cache policy mongodb-org

With the MongoDB source removed and no package installed, this command returns no package data. That empty result confirms Ubuntu no longer has an active MongoDB repository configured.

MongoDB on Ubuntu FAQ

Is MongoDB supported on Ubuntu 26.04 yet?

Not through MongoDB’s native Ubuntu repository right now. The resolute/mongodb-org/8.2, 8.0, and 7.0 repository paths all returned 404, so the standard upstream APT method still targets Ubuntu 24.04 and 22.04.

Should I install MongoDB 8.2 or 8.0 on Ubuntu?

Use MongoDB 8.2 for new deployments because it is the current stable release. Use MongoDB 8.0 only when an application, driver matrix, or upgrade plan needs the 8.0 major line. On Ubuntu 24.04 and 22.04, both series are available from MongoDB’s repository, while 7.0 is limited to Ubuntu 22.04 within the current LinuxCapable scope.

Why does MongoDB 8.2 use the 8.0 signing key on Ubuntu?

MongoDB’s Ubuntu 8.2 repository is currently signed with the MongoDB 8.0 release key. The working key file is the server-8.0.asc key, and MongoDB’s own troubleshooting page references the same key fingerprint when NO_PUBKEY errors appear.

Can I use Ubuntu’s mongodb package instead of mongodb-org?

Not if you want the current MongoDB Community Edition track. MongoDB’s official docs say the Ubuntu mongodb package is not maintained by MongoDB and can conflict with mongodb-org, so remove those older Ubuntu packages before adding the upstream repository.

Conclusion

MongoDB Community Edition is running on Ubuntu from the upstream APT repository, with mongod managed by systemd and mongosh ready for admin work. If the server needs remote clients, install and configure UFW on Ubuntu before you open port 27017 beyond trusted networks. If a relational database fits the workload better, you can also install PostgreSQL 17 on Ubuntu.

Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: