Uninstall MongoDB Completely on Debian/Ubuntu-Based Linux
If you encounter some problems with your MongoDB server and trying to reinstall it or just want to uninstall it, the following will cover how to purge Mongo completely (including dependencies, configuration file, logs and database storage) on Debian/Ubuntu-based Linux distros (e.g. Linux Mint, Pop!_OS, Elementary OS).

/usr/bin/mongod
) running in the backgroundStop Service
Stop the MongoDB daemon (mongod.service
) so no more data will be written to the disk:
sudo systemctl stop mongod
Bash
Uninstallation
Uninstall MongoDB server and its related packages (tools, client, etc.) from our system:
sudo apt purge mongodb*
Bash
Remove the unused dependencies:
sudo apt autoremove
Bash
Clean Up
Although MongoDB is now uninstalled, there are still some files left to clean.
Configuration File (Optional)
Remove the configuration file (/etc/mongod.conf
):
sudo rm -f /etc/mongod.conf
Bash
Logs (Optional)
Remove the logs in /var/log/mongodb
:
sudo rm -rf /var/log/mongodb
Bash
Database Storage (Optional)
Remove the database storage in /data/db
(default value of dbPath
):
sudo rm -rf /data/db
Bash