MongoDB installation in Ubuntu server

                                                                                                                         

Installation of MongoDB in Ubuntu Server.

— We will be installing MongoDB using package manager. For that first we need to add GPG key.

Login to Ubuntu machine and enter below command :

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

— We need to then open package manager’s source list file and add below line in the end of it.

deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

  • sudo vim /etc/apt/sources.list ( Command to open the file )
  • Shift + g ( Entering this in the file will bring you to the end of the file)
  • deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen (Enter this line in the end of the file )
  • Save and exit the file

— Run below three commands :

  • sudo apt-get update ( It downloads the package lists from the repositories and “updates” them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.)
  • sudo apt-get upgrade ( It will fetch new versions of packages existing on the machine if APT knows about these new versions by way of apt-get update)
  • sudo apt-get install mongodb-10gen ( It will install mongodb)

— You can check success of mongodb installation by running command:

ps -ef | grep mongo

As you can see from the output command of the “ps -ef | grep mongo”, the config file of mongodb is at “/etc/mongodb.conf“

On opening this file, we can find the dbpath location and logpath

— We can keep the default value as the dbpath and logppath or can update the value to our defined path. To update the value, we need to first create those directories, change permissions of those directories, then update the config file and finally restart mongodb server.

  • Create directories:

sudo mkdir -p /home/techiematerials/data/db

sudo mkdir -p /home/techiematerials/data/log

  • Change permission of the created directories ( As the MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account).

Command :

sudo chown mongodb:mongodb data/ -R

  • Update config file

  • Restart mongodb service.

sudo service mongodb stop

sudo service mongodb start

— Your mongodb is installed in the Ubuntu server. Just hit “mongo” command and can use mongdb.

                                                                                                                         

Leave a Reply

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