Ubuntu – How to uninstall MongoDB and reinstall the latest version

11.10mongodb

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 127.0.0.1 shell/mongo.js:84
exception: connect failed

Best Answer

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:

mongo

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.

Related Question