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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To completely remove MongoDB from an Ubuntu server, back up anything you need, stop mongod, purge the correct MongoDB package family, and delete the configured database and log directories. The default directories are /var/lib/mongodb and /var/log/mongodb, but /etc/mongod.conf may define different locations. An apt remove alone is not sufficient because it can leave configuration files behind.

This procedure is destructive. It removes MongoDB programs, configuration, databases, and logs, and it cannot be reversed without a usable backup. Confirm the edition, paths, and backup before running any deletion command.

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

What complete removal actually does

A complete uninstall has four separate parts:

  • Stop the running MongoDB daemon so files are not being written while you remove them.
  • Purge the package family that installed MongoDB, including its package-managed configuration.
  • Remove the database directory and log directory, including any custom locations configured for this server.
  • Verify that the service, packages, configuration, data, and logs are no longer present.

MongoDB’s official documentation describes the operation plainly: “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.” Treat the commands below as a final destruction procedure, not as a temporary troubleshooting step.

Before you uninstall: protect data and record the installation

Back up databases and configuration

Export every database that must survive the removal. Preserve any configuration, certificates, key files, scripts, or service overrides that you may need when rebuilding the server. Keep the backup outside the directories you are about to delete; a backup stored under /var/lib/mongodb or /var/log/mongodb will be removed with the installation. An external drive can be used as optional physical backup storage, but no particular storage product is required.

#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

Do not continue merely because the server appears idle. A quiet server can still contain the only copy of an application’s data. Check with the application owner or your change record if you are unsure whether the databases are still required.

Determine whether the installation is Community or Enterprise

The package glob differs by edition. Using the wrong glob can leave the actual MongoDB packages installed, so identify the package family before purging.

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.
MongoDB edition Package family to purge Configuration file to inspect Default database path Default log path
Community Edition mongodb-org* /etc/mongod.conf /var/lib/mongodb /var/log/mongodb
Enterprise Edition mongodb-enterprise* /etc/mongod.conf /var/lib/mongodb /var/log/mongodb

Do not infer the edition from the service name: both editions use the mongod service. Confirm the package family installed on this host and use only the matching purge command.

Read the active configuration before deleting directories

Open the configuration file while MongoDB is still installed:

sudo cat /etc/mongod.conf

Find the storage database path, normally expressed as storage.dbPath, and the system log path, normally expressed as systemLog.path. MongoDB documentation lists /var/lib/mongodb and /var/log/mongodb as defaults, but either value can be customized. Write down every non-default path before you remove packages or directories. If the file is missing, determine the paths from your deployment records rather than guessing.

Step 1: Stop MongoDB cleanly

On an Ubuntu server managed by systemd, stop the daemon first:

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
sudo systemctl stop mongod

The official uninstall instructions also document the service compatibility command:

sudo service mongod stop

Use the command style supported by your host. Do not delete the data directory while mongod is still running. A running process can keep files open, continue writing logs, or make the removal appear incomplete.

If the stop command reports an error, pause the uninstall and resolve that state before proceeding. Record the message, check whether the daemon actually stopped, and avoid substituting directory deletion for a clean stop. The next step is safe only after MongoDB is no longer running.

Step 2: Purge the MongoDB packages

Community Edition

For a Community Edition installation, purge the complete package family:

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

The wildcard targets the MongoDB Community package family rather than a single executable package. Purging removes package-managed configuration files as well as the installed applications.

Enterprise Edition

For an Enterprise Edition installation, use the Enterprise package family instead:

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
sudo apt-get purge mongodb-enterprise*

Do not run both commands automatically. Select the one that matches the packages installed on this server. If you are uncertain, stop here and identify the edition; a partial purge is not the same as complete removal.

Why apt remove is not enough

apt remove can uninstall program files while leaving package configuration behind. The complete MongoDB procedure uses apt-get purge for the relevant package family so those package-managed configuration files are removed as part of the package operation. Purging packages still does not remove every database or log directory, which is why the next step is required.

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

Step 3: Delete the database and log directories

Remove the default locations only when they are active

After the package purge, confirm that the paths you recorded from /etc/mongod.conf are the defaults. If the active database path is /var/lib/mongodb and the active log path is /var/log/mongodb, remove them with:

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

The order is not important, but both directories matter: deleting only the data directory leaves logs, while deleting only the logs leaves the databases. These commands permanently remove the databases and MongoDB logs stored in those directories.

Handle customized paths

If storage.dbPath points somewhere other than /var/lib/mongodb, do not substitute the default path. Remove the configured database directory after verifying that the backup is complete and that the path belongs to this MongoDB instance. Apply the same rule to systemLog.path: if logs are stored outside /var/log/mongodb, remove that configured log location instead of assuming the default.

Custom paths are the most common reason a server appears to retain MongoDB data after an apparently successful package removal. Package commands operate on packages and their managed files; they cannot safely guess which administrator-created directories contain the instance’s data.

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.
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

Use extra caution with shared or parent directories

Delete the specific MongoDB directory, not an entire parent directory that may contain unrelated services. Before using rm -r, compare the path character by character with the value in the configuration and your backup record. If a custom path is shared with another application, do not remove the shared directory; isolate and remove only the MongoDB data or log content after confirming ownership.

Step 4: Verify that the installation is gone

Check the service state

The official uninstall guidance recommends checking the service after removal:

service mongod status

A status result showing that the service is absent or no longer running is consistent with removal. If the service is still active, stop it and investigate before deleting anything else. If the command reports that no such service exists, that is expected after the service definition has been removed; continue with package and path checks.

Inspect installed packages

Inspect the host’s installed package list and confirm that the MongoDB package family you targeted is no longer installed. Check for both possible families if the server’s history is unclear: a Community package left behind after an Enterprise purge, or an Enterprise package left behind after a Community purge, means the removal is incomplete. The package check is separate from the service check because a service can be stopped while packages remain installed.

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

Check configuration, data, and logs

Verify that the package configuration file, database directory, and log directory are gone from the paths used by this instance. Also check every custom path recorded before the purge. A default-directory check alone cannot establish complete removal when dbPath or the system log path was customized.

Do not mistake an unrelated directory with a similar name for an active MongoDB installation. Use the paths from the configuration and deployment records as the authority, and preserve any files that belong to another application.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decision guide: which command should you use?

Situation Action Reason
Ubuntu host uses systemd sudo systemctl stop mongod Stops the daemon through systemd before removal.
Host uses the service compatibility interface sudo service mongod stop Stops the same daemon through the documented compatibility command.
Community Edition packages are installed sudo apt-get purge mongodb-org* Purges the Community package family and its package-managed configuration.
Enterprise Edition packages are installed sudo apt-get purge mongodb-enterprise* Purges the Enterprise package family and its package-managed configuration.
Configuration uses default paths Remove /var/lib/mongodb and /var/log/mongodb These are the documented default database and log directories.
Configuration uses custom paths Remove the configured database and log locations after backup confirmation Deleting only the defaults would leave the actual data or logs behind.

Troubleshooting incomplete removal

“I ran apt remove, but MongoDB is still present.”

Package removal and complete removal are different operations. Run the edition-appropriate apt-get purge command, then remove the configured data and log directories. Finally, check the service state, installed packages, and all paths from /etc/mongod.conf. Do not conclude that MongoDB remains solely because a directory exists; first determine whether it is an active configured path or an unrelated leftover.

“The mongod service still appears.”

Check the service with service mongod status. If it is running, stop it before any directory deletion. If it is stopped but still listed, inspect the installed package family and service definition state. A stopped service entry does not prove that databases remain, while a running service proves that removal is not complete.

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

“The default directories are gone, but disk usage remains.”

Re-read the configuration and look for customized storage.dbPath and systemLog.path values. MongoDB may have stored data or logs outside the defaults. Check those exact locations and any deployment documentation before removing them. Do not delete arbitrary large directories merely because their names contain “mongo.”

“I deleted the packages before reading mongod.conf.”

Stop and reconstruct the configuration from your backup, server records, or deployment documentation before deleting directories. The package purge can remove the package-managed configuration, but it does not establish where custom data was stored. If you cannot identify the data and log paths confidently, do not claim complete removal; preserve possible data until its ownership and backup status are known.

“I need MongoDB back after deleting it.”

Reinstallation can restore software, but it cannot recreate databases or custom settings that were deleted. Recovery depends on the backup and configuration copies made before removal. This is why the backup checkpoint comes before stopping the service and why the deletion commands should be treated as irreversible.

Reproducible removal checklist

  1. Confirm that the databases, configuration, and logs are no longer needed, or export and preserve them.
  2. Identify whether the host uses the mongodb-org* Community family or the mongodb-enterprise* Enterprise family.
  3. Read /etc/mongod.conf and record storage.dbPath and systemLog.path.
  4. Stop MongoDB with sudo systemctl stop mongod or sudo service mongod stop.
  5. Purge the matching package family with sudo apt-get purge mongodb-org* or sudo apt-get purge mongodb-enterprise*.
  6. Delete the active database and log directories, using the defaults only when the configuration confirms them.
  7. Run service mongod status and inspect installed packages.
  8. Verify that the configuration file, default or custom data path, and default or custom log path are no longer present.

What “completely removed” means at the end

You can describe MongoDB as completely removed only when the daemon is stopped or absent, the correct package family has been purged, package-managed configuration is gone, and the database and log directories identified by the instance configuration have been deleted. If you intentionally retained a backup or a configuration copy outside those locations, that does not mean MongoDB remains installed; it means you preserved material needed for recovery.

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

The critical distinction is between removing the executable packages and removing the instance’s state. Ubuntu package commands handle the former. The configured paths, backup confirmation, and final verification handle the latter.

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

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.