Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › Database Management

How to Completely Remove MongoDB from an Ubuntu Server

By Freedom251 Team · · 7 min read

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To completely remove MongoDB from an Ubuntu server, stop the mongod service, purge the correct MongoDB package family, and delete the configured database and log directories. This removes the server software, configuration, databases, and logs. It cannot be undone without a backup.

MongoDB’s official documentation describes this as a destructive operation: “This process will completely remove MongoDB, its configuration, and all databases. This process is not reversible, so ensure that all of your configuration and data is backed up.” Confirm your backup before running any deletion command.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What “completely remove MongoDB” means

An ordinary package removal can leave configuration files, database files, logs, or a service definition behind. A complete removal has three separate parts:

  • Stop the running mongod daemon.
  • Purge the installed MongoDB package family and its configuration files.
  • Delete every database and log directory used by that installation.

The final step is what removes the databases themselves. If you only want to uninstall the software while preserving data for a later reinstall, do not perform the directory-deletion step.

#1 Best Overall
Sale
Western Digital 8TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Backup Software - WDBBGB0080HBK-NESN
  • Massive capacity, up to 22TB capacity. (1TB = one trillion bytes. Actual user capacity may be less depending on operating environment.).Specific uses: Personal
  • Includes software for device management and backup with password protection (Download and installation required. Terms and conditions apply. User account registration may be required.)
  • 256-bit AES hardware encryption
  • SuperSpeed USB (5 Gbps); USB 2.0 compatible
  • Trusted storage built with WD reliability

Before you start: protect data and identify the installation

Back up anything you may need

Export the databases and copy any configuration or certificates required by your applications. Store the backup somewhere separate from the Ubuntu server; an external drive is one possible destination, but no particular storage product is required.

Do not rely on the package purge as a backup method. Once the database and log directories are removed, MongoDB cannot reconstruct their contents. Treat the deletion as permanent unless you have a tested backup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Determine whether the server uses Community or Enterprise packages

The package glob must match the edition that is installed:

MongoDB edition Package family to purge
Community Edition mongodb-org*
Enterprise Edition mongodb-enterprise*

Using the wrong family can leave the installed packages untouched. If you are unsure which edition is present, inspect the package names listed by your system’s package manager before choosing a purge command.

Read the active configuration first

Open /etc/mongod.conf while MongoDB is still installed. Record the values for storage.dbPath and systemLog.path. The documented defaults are:

  • Database files: /var/lib/mongodb
  • Log files: /var/log/mongodb

Those paths can be customized. A complete removal must delete the actual configured locations, not just the defaults. If the configuration points to another disk or directory, preserve that path information until after you have stopped the service and confirmed your backup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty

Complete removal procedure

1. Stop MongoDB before changing files

On an Ubuntu server managed by systemd, run:

sudo systemctl stop mongod

The MongoDB uninstall documentation also records the compatibility command:

sudo service mongod stop

Use one stop command appropriate to the service-management setup. Stopping first prevents the daemon from writing to a database or log directory while packages and files are being removed.

2. Purge the package family

For a Community Edition installation, purge the entire mongodb-org family:

sudo apt-get purge mongodb-org*

For Enterprise Edition, purge the corresponding family:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt-get purge mongodb-enterprise*

apt-get purge removes the matching packages and their package-managed configuration files. The asterisk is intentional: MongoDB installations commonly include several related packages, and purging only one package can leave the rest installed.

Review the package manager’s proposed removal list before confirming. It should correspond to the MongoDB edition you identified. If unrelated software is scheduled for removal, cancel the operation and investigate the package selection rather than accepting it blindly.

Rank #3
Sale
Western Digital 6TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Auto Backup Software - WDBBGB0060HBK-NESN
  • Massive capacity, up to 18TB capacity (1 1TB = one trillion bytes. Actual user capacity may be less depending on operating environment.).Specific uses: Business, personal
  • Includes software for device management and backup with password protection (Download and installation required. Terms and conditions apply. User account registration may be required.)
  • 256-bit AES hardware encryption
  • SuperSpeed USB (5 Gbps); USB 2.0 compatible

3. Delete the database and log directories

Only continue after confirming the backup and checking /etc/mongod.conf. When the installation uses the documented default paths, remove them with:

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

The first command removes MongoDB logs. The second removes all database files, including every database stored by that instance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If storage.dbPath or systemLog.path specifies different locations, substitute those configured directories instead. Do not run the default-path commands as a substitute for checking the configuration: deleting the wrong directories can leave MongoDB data behind, while deleting a path that belongs to another service can cause unrelated damage.

When separate custom directories are used, verify each path character by character before applying rm -r. This command is recursive and does not provide a recovery mechanism once the files are deleted.

4. Verify that the service and installation are gone

Check the service state with the command documented by MongoDB:

service mongod status

A successful complete removal should not show a running MongoDB daemon. Depending on the Ubuntu and package-manager state, the command may report that the service is not found or that it is inactive. Either result is different from a running service; investigate further if it reports an active process.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
WD 6TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBR9S0060BBK-WESN
  • World’s First 6TB 2.5” Portable Hard Drive
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption

Also inspect the installed package list and the configuration paths you recorded earlier. Confirm that:

  • The selected MongoDB package family is no longer installed.
  • The configured database directory has been removed if data deletion was intended.
  • The configured log directory has been removed if log deletion was intended.
  • No alternate dbPath or log path was overlooked in /etc/mongod.conf.

If the service still starts, stop it again and determine which package or service definition remains before deleting additional files. Do not assume that an empty default directory proves that a custom data path was removed.

Default paths versus customized paths

The default locations are useful only when the active configuration uses them. MongoDB’s Enterprise Ubuntu documentation identifies /var/lib/mongodb as the default database path and /var/log/mongodb as the default log path, while also noting that both settings can be changed.

Configuration setting Default location What to remove for a complete uninstall
storage.dbPath /var/lib/mongodb The directory currently assigned to storage.dbPath
systemLog.path /var/log/mongodb The directory or log path currently assigned to systemLog.path

A custom path may be on a separate mounted volume. If that volume contains other files, remove only the MongoDB-specific directory rather than deleting the entire mount point. Preserve any files that are outside the configured MongoDB paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why apt remove may leave MongoDB behind

apt remove is not the complete procedure described by MongoDB’s documentation. It can leave package configuration files, and it does not by itself remove the database and log directories. That is why a server may still contain /etc/mongod.conf, /var/lib/mongodb, or /var/log/mongodb after an ordinary removal.

If you already ran apt remove, use the same recovery sequence:

Best Value
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty
  1. Read any remaining /etc/mongod.conf to identify custom paths.
  2. Stop mongod with sudo systemctl stop mongod or sudo service mongod stop.
  3. Purge the matching mongodb-org* or mongodb-enterprise* package family.
  4. Delete the configured database and log directories only after confirming the backup.
  5. Run service mongod status and inspect the package and path state.

This sequence addresses both leftovers from the package manager and files that packages intentionally do not remove because they may contain user data.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If you want to remove MongoDB but keep the databases

Stopping the service and purging packages are separate from deleting the data. You can stop after the purge if your goal is to remove the MongoDB software while retaining the database files for a future installation or migration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Stop mongod.
  • Purge the appropriate package family.
  • Do not run the rm -r commands for the configured database directory.
  • Keep a written record of the existing storage.dbPath and log settings.

Leaving the data directory in place means MongoDB has not been completely removed in the destructive sense, but it avoids deleting the databases. Label the server or maintenance record clearly so that a later administrator does not mistake retained files for an accidental leftover.

Troubleshooting common failure modes

The stop command says the service is already inactive

An inactive service is not writing new database files, so continue by checking the package family and configuration paths. If the service status still shows an active process, do not delete directories until that process has stopped.

The default directories are gone, but MongoDB data remains

Reopen the configuration and inspect storage.dbPath. A custom path is the most likely explanation. Check the configured log path separately; data and logs do not have to be stored in the same directory.

The package purge removes only some MongoDB packages

Confirm whether the server uses Community or Enterprise naming. Run the purge command for the matching family, including the wildcard. Mixing the two globs or omitting the wildcard can leave related packages installed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

service mongod status still reports a service

First distinguish an inactive service record from a running daemon. If it is active, stop it and inspect which MongoDB packages remain. If it is inactive but the package list is empty and the configured directories are gone, the status command may simply be reporting a leftover service reference rather than a running database.

You are unsure whether the backup is usable

Pause the removal. The official warning is specifically about irreversibility: without a usable export or copy of the required configuration and data, deleting the directories can permanently destroy the databases. Validate the backup before proceeding.

Quick Recap

SaleBestseller No. 1
Western Digital 8TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Backup Software - WDBBGB0080HBK-NESN
Western Digital 8TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Backup Software - WDBBGB0080HBK-NESN
256-bit AES hardware encryption; SuperSpeed USB (5 Gbps); USB 2.0 compatible; Trusted storage built with WD reliability
$329.99
Bestseller No. 2
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$132.10
SaleBestseller No. 3
SaleBestseller No. 4
WD 6TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBR9S0060BBK-WESN
WD 6TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBR9S0060BBK-WESN
World’s First 6TB 2.5” Portable Hard Drive; Slim durable design to help take your important files with you
$259.00
Bestseller No. 5
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$181.00

Final removal checklist

  • Database exports and required configuration have been backed up outside the server.
  • The installation edition has been identified as Community or Enterprise.
  • /etc/mongod.conf has been read before any deletion.
  • Both storage.dbPath and systemLog.path have been recorded.
  • mongod has been stopped.
  • The matching package family has been purged with apt-get purge.
  • The active database and log directories, including custom paths, have been removed if full data deletion was intended.
  • service mongod status no longer reports a running daemon.
  • The installed package state and filesystem paths have been checked for leftovers.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Database ManagementLinux administrationMongoDBserver maintenanceUbuntu

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.