02 - MongoDB Installation

Installing MongoDB

MongoDB can be installed on a wide variety of platforms. There are setups available from installing it on Personal Computers to Enterprise Servers. Note that MongoDB supports both 32 and 64 bit architecture. Here is a list of Operating Systems where it is been supported to perform installation –

Amazon Linux – MongoDB  as well as MongoDB Enterprise is supported

Debian 7.1 – MongoDB supported as well as MongoDB Enterprise is supported

RedHat/CentOS 6.2+ – MongoDB as well as MongoDB Enterprise are supported

SUSE 11 – MongoDB as well as MongoDB Enterprise is supported

Ubuntu LTS 12.04 – MongoDB   as well as MongoDB Enterprise is supported

Ubuntu LTS 14.04 – MongoDB   as well as MongoDB Enterprise is supported

Windows Server 2012 – MongoDB   as well as MongoDB Enterprise is supported


Mac OSX 10.6+ – MongoDB is supported but MongoDB Enterprise is not supported

RedHat/CentOS 5.5+ – MongoDB is supported but MongoDB Enterprise is not supported

RedHat/CentOS 5.7+ – MongoDB is supported as well as MongoDB Enterprise is supported

RedHat/CentOS 7.0+ – MongoDB is supported as well as MongoDB Enterprise is supported

SmartOS – MongoDB is supported but MongoDB Enterprise is not supported

Solaris 11 / SunOS 5.11 on x86 – MongoDB is supported but MongoDB Enterprise is not supported

Windows Server 2008 R2 – MongoDB is supported as well as MongoDB Enterprise is supported

Installation of MongoDB on RedHat Enterprise Linux OR CentOS Linux

We will perform this installation using .rpm package. Though some distributions have their own packages but the official MongoDB packages are generally are more up-to-date.

Step 1

List of MongoDB Packages

MongoDB gives packages which are officially supported MongoDB built ups in its self-repository that provides MongoDB distribution the following packages:

mongodb-org – A meta package to automatically install following four component packages:

  1. mongodb-org-server – Contains mongod daemon, corresponding configuration and init scripts
  2. mongodb-org-mongos – Contains mongos daemon
  3. mongodb-org-shell – Contains mongo shell
  4. mongodb-org-tools – Contains below mentioned MongoDB tools:
  • mongoimport
  • mongodump
  • mongoexport
  • mongofiles
  • mongooplog
  • mongoperf
  • mongorestore
  • mongostat
  • mongotop

Step 2

MongoDB Control Scripts

The mongodb-org package has various control scripts that include init script /etc/rc.d/init.d/mongod. The following functions are performed by these scripts:

  • Start daemon process
  • Stop daemon process
  • Restart daemon processes

Package performs configuration of MongoDB using /etc/mongod.conf file along with the control scripts. Please note that in version 3.0.2 there are no control scripts present for mongos. Mongos process is being used in sharding only.

Step 3


Very important thing to remember is that for the production deployments, make a practice to run MongoDB on the 64 bit systems. Default configuration file /etc/mongod.conf is provided by 3.0 series package contains a bind_ip which is set to by default as We need to change this setting as per our requirement of environment before actually initializing replica set.

Step 4

Configuration of MongoDB package management system (yum)

You are required to create /etc/yum.repos.d/mongodb-org-3.0.repo file in order to install MongoDB directly using yum. Along with this, you need to use the suitable repository file to provide the specification of latest stable release of MongoDB. Depending on the MongoDB release, you would be using the required repository. In the cases, where you want to install MongoDB packages that should belong to a particular release series (2.4 or 2.6) then you can mention that release series in repository configuration. Also note that the .repo file for each and every release can be found in repository itself. Always remember that odd numbered minor release versions such as 2.5 are for development and not suitable for production usage.

Step 5

Install MongoDB packages and associated tools

During the installation time of packages, you always choose between following 2 options:

  • Whether you want to install the current release
  • Or you want the previous one

We provide “-y mongodb-org” after “sudo yum install”   to install latest stable version of MongoDB. In order to install a specific release of MongoDB, we specify each and every component package individually and then append the version number with the package name. first we need to write “sudo yum install –y” then mongodb-org-<<version number>> mongodb-org-server-<<version number>> mongodb-org-shell-<<version number>> mongodb-org-mongos-<<version number>> mongodb-org-tools-<<version number>>

This means we can specify any of the available versions of MongoDB. Also note that yum will upgrade the packages when a newer version becomes available. If we want to prevent the unintended upgrades then we need to pin the package. For this purpose we need to add some exclude directive to the file /etc/yum.conf.

Also important to remember that versions of the MongoDB packages just before 2.6 use altogether a different repo location.

Installing MongoDB on PC

Step 1: Download the MongoDB software (As per your Operating System) from website http://www.mongodb.org/downloads

For the demonstration purpose in this tutorial, we will show you the same in Windows 8.

Step2: Create a folder named ‘MongoDB’ in “C” drive

Step3: Unzip the downloaded software and copy the unzipped folder in MongoDB folder

Step4: MongoDB Server requires a ‘DATA’ directory and a ‘LOG’ directory. Hence we need to create two folder as ‘data’ and ‘log’ under MongoDB folder. In the log folder create a file named ‘mongodb.log’ so that MongoDB will write the log information in it

Step5: Under MongoDB folder create a file named ‘mongo.config’, this file will hold all the configuration information. Add the data and log directory information in it. Additionally mention a parameter “diaglog=3” for providing the read and write permission

So the directories will look like as:

MongoDB Directory

MongoDB Directory


MongoDB Log Directory

MongoDb Log Directory

Content of mongo.config file

Content of MongoDB Config file



Let us start the Server. Go to Command prompt and open the directory “C:\MongoDB\mongodb-win32-x86_64-2008plus-2.4.9\bin”. Here it is how it will look like:

Starting MongoDB Server

Then start the MongoDB Server using command “mongod.exe --config=” C:\MongoDB\mongo.config”

Command to start MongoDB Server

Now the server is ON and we can open a shell to check whether it is working. Open another command prompt window and go to the bin directory. Then execute the command mongo to begin the mongo shell

Checking MongoDB

By default it will get connected to the test database. You can use db command to check to which database it is connected to

Check MongoDB connection

To quickly check available commands use help command

MongoDB command help


Like us on Facebook