How to Install MongoDB on Ubuntu

MongoDB is a free and open-source NoSQL document database used commonly in modern web applications.


Step 1 — Adding the MongoDB Repository

At first, navigate to http://repo.mongodb.org/apt/ubuntu/dists/ and choose your Ubuntu version. The Ubuntu version name is at https://wiki.ubuntu.com/Releases

Then navigate to http://keyserver.ubuntu.com/pks/lookup?op=vindex&search=packaging%40mongodb.com&fingerprint=on, get the key from the version exist on both repo.mongodb.org and keyserver.ubuntu.com. MongoDB 3.4 is my choice.


Run the following command:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv A15703C6

Create a list file for MongoDB:
$ echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

Update the package list:
$ sudo apt update

Step 2 — Installing and Verifying MongoDB

Run the following command:
$ sudo apt install -y mongodb-org

Check MongoDB service status:
$ service mongod status

Run MongoDB Community Edition
  • Start:
    $ sudo service mongod start
  • Stop:
    $ sudo service mongod stop
  • Restart:
    $ sudo service mongod restart
Uninstall MongoDB Community Edition
This process will completely remove MongoDB, its configuration, and all databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding.
$ sudo service mongod stop
$ sudo apt purge mongodb-org*
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb


Read MongoDB manual - Installation here https://docs.mongodb.com/manual/installation/#tutorial-installation

No comments:

Post a Comment