Uninstall MongoDB in Ubuntu via command line in 3 easy steps

By | December 27, 2015

Step 1: Stop the service

sudo service mongod stop

Step 2: Remove packages

sudo apt-get purge mongodb-org*

Step 3: Remove data directories

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

-r means recursive

Reference: https://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-ubuntu/

13 thoughts on “Uninstall MongoDB in Ubuntu via command line in 3 easy steps

  1. Tadese

    when i type this command sudo service mongod stop the ff error is raised
    Failed to stop mongod.service: Unit mongod.service not loaded.

    Reply
  2. worhtles

    How about just check the offical mongodb docs?

    Oh; wait; it’s exactly the same as your answer…

    Reply
  3. Luka

    Don’t forget to

    rm -rf /etc/

    folder as well (If you don’t intend on keeping the data). Mongo pre-allocates file sizes, meaning even if you have an almost empty database, the files still occupy a substantial amount of storage.

    Reply
    1. anonymous captain

      Do not rm -rf /etc/ that will delete the entire etc folder with everything else

      Reply
    2. Stuart

      Be careful with that command, you don’t want to delete all the “etc” directory

      Reply
    3. David

      DONT TRY THIS. It will delete the entire etc folder. A$$hole.

      Reply
      1. David

        Why does the admin accept such a comment?? Do you really understand this stuff? Or just copying from askubuntu?

        Reply
        1. cloudnthings Post author

          Good point! Seems like this comment slipped through. Thanks for picking this up.

          Reply
  4. Armando

    Thank you a lot!

    I install the wrong version for my ubuntu, and when i tried to install the correct version it was impossible.

    This command sudo rm -r /var/log/mongodb solve the problem. thanks

    Reply
  5. Sam

    Luka’s response above of rm -rf /etc/ will completely screw your computer.

    Don’t run this command. It will delete the entire directory that contains all your config files.

    Reply

Leave a Reply

Your email address will not be published.