68
votes

I have installed MongoDB 3.0.1 following the commands in Install MongoDB Community Edition on Ubuntu on my ubuntu 14.04 64 bit system and I installed Robomongo interface to use that.

When I try to connect MongoDB using Robomongo I get an error that authorization failed. I found Add support for SCRAM-SHA-1 authentication (MongoDB 3.0+) which explains that Robomongo 0.8.5 doesn't support MongoDB 3.0.X fully.

In response, I want to remove MongoDB 3.0.1 and install MongoDB 2.2.

I tried the following commands:

 apt-get remove --purge mongodb

and also

apt-get autoremove --purge mongodb

In both cases I got the following error:

" Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?"

Any help would be appreciated.

9
Do you have access sudo privileges? If so, sudo apt-get remove --purge mongodbEric Groves
Try to run this commands from root. sudo apt-get remove --purge mongodbAnton Popov
Adding sudo worked. ThanksAnita
Not sure if it was a typo or not, but don't use MongoDB 2.2, it's very old at this point. The previous release to 3.0 (2.6) should work fine with robomongoAdam Comerford

9 Answers

133
votes
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

this worked for me

74
votes

In my case mongodb packages are named mongodb-org and mongodb-org-*

So when I type sudo apt purge mongo then tab (for auto-completion) I can see all installed packages that start with mongo.

Another option is to run the following command (which will list all packages that contain mongo in their names or their descriptions):

dpkg -l | grep mongo

In summary, I would do (to purge all packages that start with mongo):

sudo apt purge mongo*

and then (to make sure that no mongo packages are left):

dpkg -l | grep mongo

Of course, as mentioned by @alicanozkara, you will need to manually remove some directories like /var/log/mongodb and /var/lib/mongodb

Running the following find commands:

sudo find /etc/ -name "*mongo*" and sudo find /var/ -name "*mongo*"

may also show some files that you may want to remove, like:

/etc/systemd/system/mongodb.service
/etc/apt/sources.list.d/mongodb-org-3.2.list

and:

/var/lib/apt/lists/repo.mongodb.*

You may also want to remove user and group mongodb, to do so you need to run:

sudo userdel -r mongodb
sudo groupdel mongodb

To check whether mongodb user/group exists or not, try:

cut -d: -f1 /etc/passwd | grep mongo
cut -d: -f1 /etc/group | grep mongo
67
votes

I suggest the following to make sure everything is uninstalled:

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

sudo apt-get purge mongodb-10gen

sudo apt-get autoremove

This should also remove your config from

 /etc/mongodb.conf.

If you want to clean up completely and you might also want to remove the data directory

/var/lib/mongodb

33
votes

use command with sudo,

sudo apt-get autoremove --purge mongodb

OR

sudo apt-get remove mongodb* --purge

It will remove complete mongodb

23
votes

Stop MongoDB

Stop the mongod process by issuing the following command:

sudo service mongod stop

Remove Packages

Remove any MongoDB packages that you had previously installed.

sudo apt-get purge mongodb-org*

Remove Data Directories.

Remove MongoDB databases and log files.

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

Sometimes this works;

sudo apt-get install mongodb-org --fix-missing --fix-broken
sudo apt-get autoremove mongodb-org --fix-missing --fix-broken
3
votes

use sudo with the command:

sudo apt-get remove --purge mongodb  
apt-get autoremove --purge mongodb  
2
votes

This will remove MongoDB completely:

sudo apt-get remove mongodb* --purge
1
votes

To uninstalling existing MongoDB packages. I think this link will helpful.