63

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.

Grr
  • 13,093
  • 6
  • 53
  • 71
Anita
  • 2,092
  • 2
  • 14
  • 29

8 Answers8

125
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

alicanozkara
  • 3,945
  • 1
  • 21
  • 22
68

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
ettanany
  • 15,827
  • 5
  • 37
  • 56
65

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

Kevin Andrid
  • 1,795
  • 1
  • 13
  • 25
  • 1
    I would just add that if the commands above are not working, run 'apt list --installed' to find the exact name of the Mongo packages you have installed, then execute the commands Kevin has outlined with the correct names. – K997 Dec 17 '20 at 21:17
32

use command with sudo,

sudo apt-get autoremove --purge mongodb

OR

sudo apt-get remove mongodb* --purge

It will remove complete mongodb

Ition
  • 477
  • 4
  • 6
  • 1
    Note in 2021 the second command above works but the first one tends to fail on modern installs. – A_Elric Jan 12 '21 at 23:58
20

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
techyaura
  • 4,798
  • 4
  • 23
  • 30
13

Sometimes this works;

sudo apt-get install mongodb-org --fix-missing --fix-broken
sudo apt-get autoremove mongodb-org --fix-missing --fix-broken
efkan
  • 11,296
  • 5
  • 64
  • 94
3

use sudo with the command:

sudo apt-get remove --purge mongodb  
apt-get autoremove --purge mongodb  
Nimpo
  • 197
  • 2
  • 10
Shyam07
  • 31
  • 2
1

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

Community
  • 1
  • 1
Chung Le
  • 103
  • 1
  • 10