Rates TodayNIFTY25,291.1+0.98%SENSEX82,104.8+1.23%Gold 24K ₹12,469.05/g down19.59Silver ₹152.90/g down3.38
InsightforGeeks
Technology

How to Uninstall MongoDB on Ubuntu: Remove the Packages, Data and Repository

Sobin Mathew
18 Apr 2024
2 min read
Share:
How to Uninstall MongoDB on Ubuntu: Remove the Packages, Data and Repository

MongoDB leaves its database files, logs and apt repository behind when you remove the packages. Follow these steps to remove it completely from Ubuntu.

Warning: deleting /var/lib/mongodb destroys every database stored on this server. If you may need the data, back it up first:

mongodump --out ~/mongo-backup-$(date +%F)

1. Stop the service

sudo systemctl stop mongod
sudo systemctl disable mongod

On very old installs from Ubuntu's own mongodb package, the service is called mongodb instead of mongod.

2. Remove the packages

sudo apt-get purge -y "mongodb-org*"
sudo apt-get autoremove -y

If you installed Ubuntu's own package, use sudo apt-get purge -y mongodb mongodb-clients mongodb-server instead.

3. Delete the data and log directories

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

If you set a custom dbPath in /etc/mongod.conf, delete that directory too.

4. Remove the MongoDB apt repository

sudo rm /etc/apt/sources.list.d/mongodb-org-*.list
sudo rm /usr/share/keyrings/mongodb-server-*.gpg
sudo apt-get update

5. Remove the mongodb user (optional)

sudo userdel mongodb

6. Confirm

which mongod
mongod --version
dpkg -l | grep -i mongo

All three should return nothing or report that the command is not found.

Troubleshooting

  • Process still running: run ps aux | grep mongo and stop it with sudo kill <PID>.
  • Port 27017 still busy: check with sudo lsof -i :27017.
  • Using MongoDB Atlas: uninstalling the local server does not affect your cloud databases.
Tags:#Uninstall MongoDB Ubuntu# Remove MongoDB Linux# MongoDB Uninstallation Guide# Ubuntu MongoDB Removal Tutorial# Step-by-Step MongoDB Uninstall Ubuntu# How to Delete MongoDB from Ubuntu# Uninstall MongoDB Command Line Ubuntu# Cleanly Uninstall MongoDB Linux# Removing MongoDB Completely Ubuntu# Best Practices for MongoDB Uninstall Ubuntu
Found this helpful? Share it with friends & colleagues
Share:
Sobin Mathew Verified Editorial Staff

Covering financial markets, commodity rates, and practical technology insights for India. Researched and fact-checked in accordance with our Editorial Policy.

Published on 18 April 2024General Information · Disclaimer

Recommended based on your reading interest

More in Technology