Install MongoDB on Ubuntu

Install MongoDB on Ubuntu – In this tutorial, we shall learn to install MongoDB Community Edition on Ubuntu 16.04. The process should remain same for 64 bit versions of Ubuntu 14.04 and Ubuntu 12.04.

Following is a quick overview of the steps we go through while installing MongoDB on Ubuntu.

  1. Import MongoDB GPG public key
  2. Create list file for MongoDB
  3. Reload Local Package Database
  4. Install MongoDB Packages
  5. Start MongoDB
  6. Stop MongoDB

Following is a detailed step by step guide to Install MongoDB on Ubuntu.

  1. Import MongoDB GPG public key

    Open a terminal and run the following command to import MongoDB GPG public key.

  2. Create list file for MongoDB

    The list file changes from Ubuntu release to release.
    Run the corresponding command in terminal for the Ubuntu version of yours.

    Ubuntu ReleaseCommand
    Ubuntu 12.04 (Precise)echo “deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntuprecise/mongodb-org/3.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
    Ubuntu 14.04 (Trusty)echo “deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntutrusty/mongodb-org/3.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
    Ubuntu 16.04 (Xenial)echo “deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntuxenial/mongodb-org/3.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

    When run for Ubuntu 16.04 (Xenial)

  3. Reload Local Package Database

    Run the following command in terminal to reload local package database

  4. Install MongoDB Packages

    Running following command installs MongoDB Packages.

  5. Start MongoDB

    To start MongoDB, run the following command in terminal

    To verify if MongoDB has started, check mongodb.log whose location is/var/log/mongodb/mongodb.log

    MongoDB would be started and waiting for connections on 27017.

  6. Stop MongoDB

    To stop MongoDB, run the following command in terminal

     

Conclusion :

In this MongoDB Tutorial – Install MongoDB on Ubuntu, we have learnt to install MongoDB on Ubuntu, start MongoDB and stop MongoDB.