3
votes

How to completely uninstall mongoDB with all its instances, and re-install it.

I've tried this,

sudo service mongod stop

sudo apt-get purge mongodb-org*

sudo rm -r /var/log/mongodb

sudo apt-get autoclean

sudo apt-get autoremove

sudo apt-get purge mongodb-org*

But its giving the below error :

sudo rm -r /var/log/mongodb its giving error :rm: cannot remove '/var/log/mongodb': No such file or directory

sudo rm -r /var/lib/mongodb its giving error :rm: cannot remove '/var/lib/mongodb': No such file or directory

Now still, it's not removed completely.

reema@reema-s ~> mongo MongoDB shell version v4.0.11 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb 2019-07-25T15:45:34.860+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:344:17 @(connect):2:6 exception: connect failed reema@reema-s ~>

2

2 Answers

2
votes

Try the below steps accordingly:

First stop the mongod process

  • sudo service mongod stop

Remove any MongoDB packages

  • sudo apt-get purge mongodb-org*

Remove MongoDB databases and log files

  • sudo rm -r /var/log/mongodb

  • sudo rm -r /var/lib/mongodb

Remove MongoDB Service

  • sudo rm /etc/systemd/system/mongodb.service

For Ubuntu 20.04 LTS use this path sudo rm /lib/systemd/system/mongod.service

This should work for you.

2
votes

In addition to the above answer you may also like to run

sudo apt-get autoremove

Sometimes if multiple versions were installed this is also required.