keepcalculator

06 Numbers and Powers

Uninstall MongoDB on Mac: Full Removal Guide

Card No. 06·75015 · Updated · Standard formula, shown below

To completely uninstall MongoDB from a Mac, you must remove the application files, the database data directory, the launch agent that runs it in the background, and the shell configuration that adds its commands to your PATH. This guide covers both Homebrew and manual installs, and it tells you exactly which files to delete so nothing is left behind.

Why a Simple Drag-to-Trash Isn’t Enough

MongoDB is not a single app that lives in your Applications folder. When you install it with Homebrew, it scatters files across several system directories, and it often registers a background service that starts automatically when you log in. If you only delete the main binary, you’ll still have the database files, the service configuration, and PATH entries pointing at files that no longer exist. That can cause error messages in your terminal and leave hundreds of megabytes of data on your drive.

There are two common installation methods, and each requires a slightly different removal process. The steps below cover both the Homebrew method (the most popular) and the manual download method. Before you start, back up any databases you want to keep using mongodump.

How MongoDB Is Installed on macOS

MongoDB on macOS is typically installed in one of two ways:

  • Homebrew: installs the server (mongod), the shell (mongosh), and the tools under /usr/local (Intel) or /opt/homebrew (Apple Silicon). It also creates a launch agent at ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist if you ran brew services start.
  • Manual download: you download a tarball, extract it, and move the bin folder somewhere like /usr/local/mongodb. The database data is usually stored in /data/db or a custom path you chose.

Both methods leave behind configuration files, logs, and the actual database files. The removal steps differ mainly in how you handle the service and the PATH.

Step-by-Step: Uninstall MongoDB Installed with Homebrew

If you used Homebrew, follow these steps in order. Open Terminal and run each command.

  1. Stop the MongoDB service. If you started it with brew services, run:
    brew services stop mongodb-community
    If you ran mongod manually, press Ctrl+C in that terminal window or kill the process with pkill mongod.
  2. Uninstall the formulae. Run:
    brew uninstall mongodb-community
    If you also installed the shell or the database tools separately, uninstall those too:
    brew uninstall mongosh mongodb-database-tools
  3. Remove the launch agent. Even after uninstalling, the plist file may remain. Delete it manually:
    rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
  4. Remove the data directory. By default, Homebrew stores data in /usr/local/var/mongodb (Intel) or /opt/homebrew/var/mongodb (Apple Silicon). Delete it:
    rm -rf /usr/local/var/mongodb (adjust the path for your chip).
  5. Remove the log file. The default log is at /usr/local/var/log/mongodb/mongo.log or similar. Delete the whole log folder:
    rm -rf /usr/local/var/log/mongodb
  6. Clean up Homebrew. Run brew cleanup and brew autoremove to remove any leftover dependencies that are no longer needed.

If you get a “permission denied” error, prefix the rm commands with sudo and enter your password. Be careful with sudo rm -rf – double-check the path before pressing Enter.

Step-by-Step: Uninstall MongoDB from a Manual Install

If you downloaded MongoDB from the official site and moved the files yourself, the process is simpler but still requires several steps.

  1. Stop any running MongoDB processes. Run pkill mongod in Terminal.
  2. Delete the MongoDB folder. If you placed it in /usr/local/mongodb, delete that folder:
    sudo rm -rf /usr/local/mongodb
    If you put it elsewhere, delete that folder instead.
  3. Remove the data directory. The default is /data/db. Delete it:
    sudo rm -rf /data/db
  4. Remove the log file. If you set a log path in your config file, delete that file. Common locations include /usr/local/var/log/mongodb or a file in the MongoDB folder.
  5. Edit your shell configuration. If you added MongoDB’s bin folder to your PATH, open your ~/.zshrc or ~/.bash_profile and remove the line that looks like:
    export PATH="/usr/local/mongodb/bin:$PATH"
    Save the file, then run source ~/.zshrc to apply the change.

If you used a custom config file (for example, mongod.conf), delete that too. If you used a launch daemon (a .plist file in /Library/LaunchDaemons), remove it with sudo rm -f /Library/LaunchDaemons/org.mongodb.mongod.plist and then run sudo launchctl unload on it before deleting.

What to Do If You See “Command Not Found” After Uninstalling

If you removed MongoDB but your terminal still shows mongod: command not found, that’s actually a good sign – it means the binaries are gone. If you see a different error, like No such file or directory when opening a new terminal, your shell profile still has an old PATH entry pointing to a folder that no longer exists. Edit ~/.zshrc or ~/.bash_profile and remove the MongoDB line, then reload the profile.

If you had the Homebrew service running, you might occasionally see a popup saying “Homebrew services” failed to start. That happens when the plist file is still present but the binary is gone. Delete the plist file as described in step 3 of the Homebrew section.

Common Mistakes and How to Avoid Them

  • Forgetting the data directory. The database files can be large. If you skip this step, you’ll lose disk space and may accidentally re-use an old database if you reinstall later.
  • Deleting the wrong folder. Always double-check paths before using rm -rf. A typo like /usr/local instead of /usr/local/mongodb could wipe unrelated files.
  • Not stopping the service first. If MongoDB is running, the uninstall may fail because files are in use. Always stop the service before deleting.
  • Skipping the PATH cleanup. Even after uninstalling, your shell may still try to find mongod. Removing the PATH entry prevents confusing errors later.

What About MongoDB Compass or Other GUI Tools?

If you also installed MongoDB Compass (the graphical interface), remove it separately. If you installed it via Homebrew, run brew uninstall --cask mongodb-compass. If you downloaded it from the website, drag the app from your Applications folder to the Trash. Compass doesn’t store database data – it’s just a client – so there’s nothing else to remove.

Frequently Asked Questions

Will uninstalling MongoDB delete my databases?

Yes, if you delete the data directory. The default data directory is /usr/local/var/mongodb (Homebrew) or /data/db (manual). If you want to keep your data, run mongodump before uninstalling to create a backup folder, and then restore it later with mongorestore.

How do I check if MongoDB is still running after uninstall?

Run pgrep mongod in Terminal. If it returns a process ID, MongoDB is still running. You can stop it with pkill mongod. Also check for launch agents with launchctl list | grep mongo – if you see an entry, remove the plist file as described above.

Can I reinstall MongoDB after uninstalling?

Yes. If you used Homebrew, just run brew install mongodb-community again. If you did a manual install, download the tarball again and follow the same steps you did originally. Remember to create a new data directory before starting mongod.

Is there a difference between uninstalling MongoDB Community and MongoDB Enterprise?

The removal steps are essentially the same. The only difference is the package name – Homebrew uses mongodb-community for the free version, while Enterprise is usually installed manually and may be in a different folder. Follow the manual install steps for Enterprise.

Do I need to uninstall mongosh separately?

Yes, if you installed the MongoDB Shell (mongosh) as a separate package. With Homebrew, run brew uninstall mongosh. If you installed it manually, delete the mongosh binary and remove any PATH entries. It’s not required for the server to run, but it’s part of a complete uninstall.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →