In this article, we will walk you through the process of installing MongoDB 3.2 Community Edition on RHEL 7/6, CentOS 7/6, Fedora 23-20, Ubuntu 14.04/12.04 LTS and Debian 7 servers with the help of official MongoDB repository using .rpm and .deb packages on 64-bit systems only.

Important: Support for MongoDB 3.2 deprecated for Red Hat Enterprise Linux and CentOS 5 distributions.

Note: To install a MongoDB prior to 3.2 version, please refer to that MongoDB 3.0 install guide.

Install MongoDB in Linux

Install MongoDB 3.2 in Linux

What is MongoDB?

MongoDB is an open source no-schema and high-performance document-oriented NoSQL database (NoSQL means it doesn’t provide any tables, rows, etc.) system much like Apache CouchDB. It stores data in JSON-like documents with dynamic schema’s for better performance.

MongoDB Packages

Following are the supported MongoDB packages, comes with own repository and contains:

  1. mongodb-org – A metapackage that will install following 4 component packages automatically.
  2. mongodb-org-server – Contains the mongod daemon and releated configuration and init scripts.
  3. mongodb-org-mongos – Contains the mongos daemon.
  4. mongodb-org-shell – Contains the mongo shell.
  5. mongodb-org-tools – Contains the MongoDB tools: mongo, mongodump, mongorestore, mongoexport, mongoimport, mongostat, mongotop, bsondump, mongofiles, mongooplog and mongoperf.

Install MongoDB Community Edition 3.2 on RHEL 7/6, CentOS 7/6, Fedora 23-20, Ubuntu 14.04/12.04 and Debian 7

Step 1: Adding MongoDB Repository

First, we need to add MongoDB Official Repository to install MongoDB Community Edition on 64-bit platforms.

On Red Hat, CentOS and Fedora

Create a file /etc/yum.repos.d/mongodb-org-3.2.repo to install MongoDB directly, using yum command.

# vi /etc/yum.repos.d/mongodb-org-3.2.repo

Now add the following repository file.

name=MongoDB Repository

On Ubuntu Systems

MongoDB repository only provides packages for 14.04 LTS (Trusty Tahr) and 12.04 LTS (Precise Pangolin) long-term supported 64bit Ubuntu releases.

To install MongoDB Community Edition on Ubuntu, you need to first import the public key used by the package management system.

$ sudo apt-key adv --keyserver hkp:// --recv EA312927

Next, create a MongoDB repository file and update the repository as shown.

On Ubuntu 14.04
$ echo "deb trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update
On Ubuntu 12.04
$ echo "deb precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update

On Debian 7 Wheezy

MongoDB repository only provides packages for 64-bit Debian 7 Wheezy, to install MongoDB on Debian, you need to run the following series of commands:

$ sudo apt-key adv --keyserver hkp:// --recv EA312927
$ echo "deb wheezy/mongodb-org/3.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update

Step 2: Installing MongoDB Community Edition Packages

Once the repo installed, run the following command to install MongoDB 3.2.

# yum install -y mongodb-org [On RPM based Systems]
$ sudo apt-get install -y mongodb-org [On DEB based Systems]

To install a particular MongoDB release version, include each component package individually and add the version number to the package name, as shown in the following example:

-------------- On RPM based Systems --------------
# yum install -y mongodb-org-3.2.3 mongodb-org-server-3.2.3 mongodb-org-shell-3.2.3 mongodb-org-mongos-3.2.3 mongodb-org-tools-3.2.3
-------------- On DEB based Systems --------------
$ sudo apt-get install -y mongodb-org=3.2.3 mongodb-org-server=3.2.3 mongodb-org-shell=3.2.3 mongodb-org-mongos=3.2.3 mongodb-org-tools=3.2.3

Step 3: Configure MongoDB Community Edition

Open file /etc/mongod.conf and verify below basic settings. If commented any settings, please un-comment it.

# vi /etc/mongod.conf
path: /var/log/mongodb/mongod.log

Note: This step is only applicable for Red Hat based distributions, Debian and Ubuntu users can ignore it.

Now open port 27017 on the firewall.

-------------- On FirewallD based Systems --------------
# firewall-cmd --zone=public --add-port=27017/tcp --permanent
# firewall-cmd --reload
-------------- On IPtables based Systems --------------
# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT

Step 4: Run MongoDB Community Edition

Now it’s time to start the mongod process by issuing the following command:

# service mongod start
OR $ sudo service mongod start

You can make sure that the mongod process has been started successfully by verifying the contents of /var/log/mongodb/mongod.log log file for a line reading.

2016-02-24T04:51:54.573-0500 I NETWORK [initandlisten] waiting for connections on port 27017

Also you can start, stop or restart mongod process by issuing the following commands:

# service mongod start
# service mongod stop
# service mongod restart

Now enable mongod process at system boot.

# systemctl enable mongod.service [On SystemD based Systems]
# chkconfig mongod on [On SysVinit based Systems]

Step 5: Begin using MongoDB

Connect to your MongoDB shell by using following command.

# mongo

Command Ouput :

MongoDB shell version: 3.2.3
connecting to: test

This command will connect to your MongoDB database. Run the following basic commands.

> show dbs
> show collections
> show users
> use <db name>

Step 6: Uninstall MongoDB Community Edition

To completely uninstall MongoDB, you must delete the MongoDB applications, configuration files and directories contains any data and logs.

The following instructions will walk through you the process of removing MongoDB from your system.

On RHEL, CentOS and Fedora

# service mongod stop
# yum erase $(rpm -qa | grep mongodb-org)
# rm -r /var/log/mongodb
# rm -r /var/lib/mongo

On Debian and Ubuntu

$ sudo service mongod stop
$ sudo apt-get purge mongodb-org*
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb

For more information visit official page at

Facebook Comments

More Stuff

Emblematic Group and Mozilla Team Up to Showcase Next Generation o... Everything you share on the internet is a story. You read blog posts and watch videos that make you feel connected to people across the world. Virtual...
Latest Firefox Release is Faster than Ever With the introduction of the new Firefox Quantum browser in 2017 we changed the look, feel, and performance of our core product. Since then we have la...
Competing without a Marketing Budget: When All You Have is a Produ... This is a story about the power of a good landing page, PR efforts, and marketing strategy. The refreshing twist here is that instead of explaining ho...
The Ongoing Fiasco and Mysterious Afterlife of QuadrigaCX I’d say you were a little late to the cryptocurrency party if you haven’t heard about the ongoing catastrophe that’s been QuadrigaCX these past six ...
Spread the love

Posted by News Monkey