How to install Mongo DB on Ubuntu 16.04

MongoDB is a cross-platform, document oriented, No Sql database. MongoDB provides high performance, high availability, and easily scalable. MongoDB works on concept of collection and document. The official Ubuntu 16.04 MongoDB packages have not been published till now by the MongoDB maintainers. In this article i am going to explains you that “How to install MongoDB on Ubuntu 16.04

To install MongoDB on your Ubuntu 16.04 follow this steps :-

  1. First login with root user. For this press CTRL + ALT + T or open terminal and type this command
    sudo -i

    This will prompt you for your password, enter your password and press enter key.

  2. Now we need to add MongoDB repository on your Ubuntu 16.04 package repositories. By default MongoDB is already comes in Ubuntu package repositories but to install the latest version of MongoDB to Ubuntu 16.04 installation we add the official MongoDB repository to our Ubuntu 16.04 installation. To add this run this command
    sudo apt-key adv --keyserver hkp:// --recv EA312927

    Once you run this command you will see an output like



    To install any package or software in Ubuntu we use apt command. So now we have to MongoDB repository details so apt can know from where it need to download the MongoDB Packages. For this use this command

    sudo echo "deb trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

    Now we need to update Ubuntu 16.04 package list. For this use this command.

    sudo apt-get update
  3. So now we are ready install the MongoDB on our machine. For this use this command
    sudo apt-get install -y --allow-unauthenticated mongodb-org

    This command will install MongoDB also some helpful tools for  management of the MongoDB. Now we need to add MongoDB as a service on Ubuntu 16.04. For this we need to create a unit file which will describe MongoDB as service to Ubuntu 16.04. So we can start or stop the MongoDB service. So now we need to create a file named mongodb.service under the /etc/systemd/system directory.  For this use this command

    sudo nano /etc/systemd/system/mongodb.service

    This command will create the file and open for editing. Now paste the below codes into this file

    Description=High-performance, schema-free document-oriented database
    ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

    Now just start the MongoDB Service. For this use this command

    sudo systemctl start mongodb

    This command will start the MongoDB. Hence, this command does not return any output. So, if need you can check service status using this command

    sudo systemctl status mongodb

    In case you want to stop the MongoDB service use this command

    sudo systemctl stop mongodb

    In case you need to restart the  MongoDB service

    sudo systemctl restart mongodb

    So, it done, We successfully installed the MongoDB on Ubuntu 16.04.

Leave a Reply

Your email address will not be published. Required fields are marked *