Cannot uninstall MongoDB

8,714

Solution 1

Try

apt-get --reinstall install mongodb

This will pretend that mongodb isn't installed already and overwrite the old files.

Afterwards you should be able to remove it like usual.

Solution 2

Just follow these commands to uninstall mongodb

sudo apt-get purge mongodb mongodb-clients mongodb-server mongodb-dev

sudo apt-get purge mongodb-10gen

sudo apt-get autoremove

Solution 3

Uninstall and remove Mongo packages.

$ sudo apt-get purge mongodb-org*

Check if related directories removed

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

Recheck for autoremove any remaining mongo packages

$ sudo apt-get autoremove

Configure your directory

$ sudo dpkg --configure -a

Force install anything required

$ sudo apt-get install -f

Re-install from https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Finally restart your Ubuntu and check status of Mogodb server as you did earlier.

Share:
8,714

Related videos on Youtube

Zanna
Author by

Zanna

Updated on September 18, 2022

Comments

  • Zanna
    Zanna almost 2 years

    It seems that following the official MongoDB installation instructions when installing on Debian direct you to a world of pain.

    First, it did not install correctly, so now I am trying to remove all installed MongoDB packages to be able to start from scratch.
    But frustratingly, because it (presumably) did not install cleanly, it won't uninstall.

    Originally, I installed it using these instructions.

    Currently, I've managed to remove every package apart from mongodb-org-server which, just won't go.

    An attempted removal results in the following:

    $ sudo apt-get remove mongodb-org-server
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages will be REMOVED:
    mongodb-org-server
    0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
    1 not fully installed or removed.
    After this operation, 23.9 MB disk space will be freed.
    Do you want to continue [Y/n]? y
    (Reading database ... 31030 files and directories currently installed.)
    Removing mongodb-org-server ...
    invoke-rc.d: unknown initscript, /etc/init.d/mongod not found.
    dpkg: error processing mongodb-org-server (--remove):
     subprocess installed pre-removal script returned error exit status 100
    invoke-rc.d: unknown initscript, /etc/init.d/mongod not found.
    dpkg: error while cleaning up:
     subprocess installed post-installation script returned error exit status 100
    Errors were encountered while processing:
     mongodb-org-server
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    

    Any idea how I can properly and cleanly get rid of MongoDB now?

  • mightypile
    mightypile over 8 years
    This generates the same error as reported by the OP.