Mongo DB Installation

The community edition of MongoDB can be installed on Ubuntu or any Debian system using simple steps

  • Import the public key
sudo apt-key adv --keyserver hkp:// --recv 0C49F3730359A14518585931BC711F9BA15703C6
  • Create List of files for MongoDB
echo "deb [ arch=amd64,arm64 ] xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

(xenial for Ubuntu 16 - Use the appropriate path for your version of Ubuntu.)

  • Reload the package database
sudo apt-get update
  • Install the latest stable version of MongoDB
sudo apt-get install -y mongodb-org

And the server is ready on your machine.

The MongoDB Server

MongoDB runs as Linux service. It can be handled in Ubuntu like any other service.

sudo service mongod start
sudo service mongod stop
sudo service mongod restart

Uninstall MongoDB

If you are done with it and want to uninstall the MongoDB server, it is equally simple. First Stop the MongoDB service. Then remove any MongoDB packages that you have installed. And finally remove the database and log files.

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