How to Install MongoDB Community Edition on CentOS/RHEL 6 and Fedora Linux Systems


In this post, we will show you how to install MongoDB community edition on Linux systems (RPM Family “Redhat /CentOS /Scientific Linux 6 and older releases of Fedora ”). This tutorial will help you to install the latest stable release “MongoDB 3.4, exists at the time of writing this post” on CentOS, RHEL and Fedora Systems.

MongoDB is a NoSQL database intended for storing large amounts of data in document-oriented storage with dynamic schemas. NoSQL refers to a database with a data model other than the tabular format used in relational databases such as MySQL, PostgreSQL, and Microsoft SQL. MongoDB features include: full index support, replication, high availability, and auto-sharding. So, let’s start our installation steps.


Before begin our installation steps, we need to check the following points.
  • Our CentOS/RHEL/Fedora must be 64-bit systems,  run the following command:
# uname -r
  • We need to run the following steps as the root user.

Step 1: Add MongoDB Yum Repository

The first step is adding the MongoDB yum repository configuration file /etc/yum.repos.d/mongodb-org-3.4.repo to our existing CentOS/RHEL yum repositories to fetch the latest stable release of MongoDB “which is 3.4 at the time of writing this article”. Depending on your OS, copy and paste the following lines into your terminal “of course without #”:

  • For CentOS/RHEL 6
# cat << EOL > /etc/yum.repos.d/mongodb-org-3.4.repo
name=MongoDB Repository
  • For Fedora Systems “12, 13, 14, 15, 16, 17, 18”
# cat << EOL > /etc/yum.repos.d/mongodb-org-3.4.repo
name=MongoDB Repository

Step 2 : Install MongoDB Server

Now, we’ll use the yum package manager to install mongodb-org package “A metapackage that will automatically install the four component packages mongodb-org-server, mongodb-org-mongos, mongodb-org-shell, and mongodb-org-tools”. Run the following command will install latest stable version available.

# yum install -y mongodb-org

Step 3 : Enable, Start, and Restart MongoDB Server

As we successfully installed all the four packages included in the mongodb-org package, we need to enable and start our MongoDB server.

To enable the server to start at reboot and boot time, run the following command:

# chkconfig mongod on

To start our MongoDB server, run the following command:

# service mongod start

To restart MongoDB server “in case of configuration changes”, run the following command:

# service mongod restart

Step 4: Checking the MongoDB Version and running service

To check installed MongoDB version, run the following command:

# mongo --version
MongoDB shell version v3.4.2
git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
 distmod: rhel65
 distarch: x86_64
 target_arch: x86_64

As you see, we are using MongoDB version v3.4.2 for CentOS/RHEL 6.

Now, we’ll check that the service is up and running by running netstat command, run the following command:

# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address     Foreign Address   State     PID/Program name 
tcp        0      0*         LISTEN    24356/mongod 
tcp        0      0*         LISTEN    4304/mysqld 
tcp        0      0*         LISTEN    1222/rpcbind 
tcp        0      0*         LISTEN    340/sshd 

As you see, our MongoDB server is up and listening on the localhost IP “”and  port “27017”. The listening IP and port is the default shipped configuration.


1. The default MongoDB configuration will accept connection only from the machine MongoDB packages installed on.
2. To change the listening IP, edit the configuration file "/etc/mongod.conf", and comment/remove the line start with "bindIp:", then restart you MongoDB server.

A final check we run is connecting to the MongoDB using command line and execute some test commands for checking proper working:

# mongo
MongoDB shell version: 3.4.2
connecting to: test

> show dbs
Semari 0.000GB
local 0.000GB
test 0.000GB

> exit

As you see, we used mongo command to connect to the server, by default we connected to the test database. Also we listed all the databases we have on the server by running “show dbs” command.

Extra Step: Uninstall MongoDB Community Edition

If you want to completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the configuration files, and any directories containing data and logs.


1. This process will completely remove MongoDB, its configuration, and all databases.
2. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding.

Run the following steps to completely uninstall MongoDB server.

  • Stop the MongoDB Server.
    You need to stop the mongod process by issuing the following command:
# service mongod stop
  •  Remove the installed Packages.
    Remove any MongoDB packages that you had previously installed.
# yum erase $(rpm -qa | grep mongodb-org)
  • Remove Data and Log Directories.
    Remove MongoDB databases and log files.
# rm -rf /var/log/mongodb
# rm -rf /var/lib/mongo

Finally, I hope this article is helpful for you.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

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