Thursday, October 6, 2016

Installing MongoDB in Ubuntu


Step-wise Installation of MongoDB in Ubuntu 


Note: We will be installing community edition of MongoDB 

Open Terminal in ubuntu using Ctrl+Alt+T.
Run the below commands :

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927


# For Ubuntu 12.04
  • echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

# For Ubuntu 14.04
  • echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
# For Ubuntu 16.04
  • echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

sudo apt-get update

# To install latest stable version of MongoDB
sudo apt-get install -y mongodb-org


To install a specific release, you must specify each component package individually along with the version number, as in the following example:

sudo apt-get install -y mongodb-org=3.2.10 mongodb-org-server=3.2.10 mongodb-org-shell=3.2.10 mongodb-org-mongos=3.2.10 mongodb-org-tools=3.2.10

Follow the below step only for Ubuntu 16.04

Create a new file at /lib/systemd/system/mongod.service with the following contents:

[Unit] 

Description=High-performance, schema-free document-oriented database After=network.target
Documentation=https://docs.mongodb.org/manual

[Service] 

User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]



WantedBy=multi-user.target

Commands for Starting, Stopping, restarting MongoDB


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


To verify that MongoDB is running , check the logs file at below path

/var/log/mongodb/mongod.log


This log file must have
[initandlisten] waiting for connections on port <port>

If the log file have above line , MongoDB is up and running.

For Uninstalling  MongoDB , please refer : UnInstalling MongoDB in Ubuntu



No comments:

Post a Comment