I need to uninstall mongodb completely from my system (Ubuntu 11.10) and install version 2.0.5.

Currently, when I run:

mongo db

I get the following error:

MongoDB shell version: 2.0.1
connecting to: db
Wed Jun 6 13:05:03 Error: couldn't connect to server shell/mongo.js:84 exception: connect failed


3 Answers 3


There are two sets of packages for MongoDB; the standard Ubuntu packages, and a set published by 10gen themselves. The standard packages are out of date, especially for older releases of Ubuntu, so it is probably a good idea to set yourself up to install from the 10gen repositories.

The error message you quote suggests that you might have already tried this, since version 2.0.1 is not a standard Ubuntu package. I suggest that first of all, you completely uninstall Mongo and clean up your system. If you have existing data that you want to keep, you could take a backup of it. By default, it is stored in /var/lib/mongodb. So if you want to take a backup, take a copy of the files from there and keep them in a safe place.

Uninstalling existing MongoDB packages

Since I'm not 100% what you've got installed, 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

Some of those commands may fail, depending on what packages you actually have installed, but that's okay.

This should also remove your config from /etc/mongodb.conf. If you want to completely clean up, you might also want to remove the data directory /var/lib/mongodb, so long as you backed it up or don't want it any more.

If you've installed by building from source or using the 10gen binary distributions, then you'll need to manually uninstall and clean up from wherever you put the binary files, config and data files.

Installing the 10gen MongoDB packages

Follow the 10gen instructions for adding their repository:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

Edit /etc/apt/sources.list, delete any lines you have already added for Mongo, and add the following single line (since 11.10 uses upstart) at the end:

deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

Note that if you add this repository using the Software Center, it will automatically add a deb-src entry, which will break apt-get. So you will need to edit your sources list by hand to add only the above line.

Then to install, run:

sudo apt-get update 
sudo apt-get install mongodb-10gen

Checking your install

Installing the packages should automatically start up the MongoDB server. So you should be able to run the client from the command line:


which should successfully connect to the test database. You can quit by typing exit.

If that fails, please update your question with further details, including the output of trying to connect and attaching your /var/log/mongodb/mongodb.log file.

  • maisapride1@maisapride1:/$ sudo apt-get purge mongodb mongodb-clients mongodb-server mongodb-dev Reading package lists... Done Building dependency tree Reading state information... Done Package mongodb is not installed, so not removed Package mongodb-clients is not installed, so not removed Package mongodb-dev is not installed, so not removed Package mongodb-server is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 406 not upgraded. -----when trying to remove, when i again give mongo it showing the vesion:MongoDB shell version: 2.0.1
    – jyothi
    Jun 6, 2012 at 10:02
  • That is fine; as I said, some of those commands may fail, depending on which packages you have installed. Those particular errors show that you did not have the standard Ubuntu MongoDB packages installed. Jun 6, 2012 at 10:07
  • Have you run the second command to remove the 10gen packages? If that removes nothing too, and you can still run the mongo client, then you must have done a manual install and you will have to delete by hand. Jun 6, 2012 at 10:30
  • can i know how to install or to update mongo db to 2.0.5 from 2.0.1
    – jyothi
    Jun 6, 2012 at 10:59
  • Installing the 10gen packages as described in my answer will give you 2.0.6. Previous versions are available for download and manual install from the MongoDB website, but I strongly suggest you stick to the packaged versions. Jun 6, 2012 at 11:15

To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps.

  1. Stop MongoDB

    Stop the mongod process by issuing the following command:

    sudo service mongod stop
  2. Remove Packages

    Remove any MongoDB packages that you had previously installed.

    sudo apt-get purge mongodb-org*
  3. Remove Data Directories.

    Remove MongoDB databases and log files.

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

Follow the steps:

  1. Remove lock file

    sudo rm /var/lib/mongodb/mongod.lock
  2. Repair mongodb

    mongod --repair
  3. Start mongodb

    sudo service mongodb start
  4. Start mongo console

  • @stumblebee: Please watch out for edit suggestions like this one! The service name is indeed mongodb as in the original version and you can verify that via the package file list. May 2, 2018 at 8:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.