Install MongoDB – Ubuntu, CentOS, Debian

This tutorial covers steps to install MongoDB in CentOS 6.4, Ubuntu or Debian Operating System.

Install MongoDB


  • Centos / Debian / Ubuntu installed on your server or your computer
  • root privileges
  • SSH access
  • Basic Linux Working Skills

MongoDB is a NoSQL open-source document database written in C++. Structure of MongoDB differs from the standard table-based relational one using JSON-like documents with dynamic schemas. In many applications, this is useful for easier and faster data manipulation.

Install MongoDB

You can use default package manager which is included inside the corresponding Linux distribution:

CentOS 6.4

To install MongoDB with yum we will first add the “epel” repository to the system:

sudo wget
sudo rpm -Uvh epel-release-6*.rpm
sudo yum makecache

After that we can start mongoDB installation:
sudo yum install mongodb mongodb-server


First thing first, we will add 10gen repository to the system


sudo echo “deb dist 10gen” >> /etc/apt/sources.list.d/mongo.list
sudo apt-key adv –keyserver –recv 7F0CEB10
sudo apt-get update

sudo echo “deb dist 10gen” >>/etc/apt/sources.list.d/mongo.list
sudo apt-key adv –keyserver –recv 7F0CEB10

Followed by:
sudo apt-get update

After this we can start the installation:
sudo apt-get install mongodb-org

You will be asked to confirm the installation.

You may have to start the service manually after the installation in CentOs:
sudo /etc/init.d/mongod start


In fact, In Debian/Ubuntu, service is started automatically by the system.

Test MongoDB service is working

The default port for MongoDB is 27017. However, default port and other settings can be changed in the configuration file of MongoDB:
sudo nano /etc/mongod.conf

One must restart the MongoDB service after making any changes to the configuration file
sudo /etc/init.d/mongod restart

In order to check its functionality you can run the following command:

This opens a new screen which starts with “>”.Type “help” inside the MongoDB terminal and you will get full command list.

To access MongoDB from a remote server, you should make sure that the default port 27017 or any new customized port is allowed inside the server’s firewall:
sudo iptables -A INPUT -p tcp –dport 27017 -j ACCEPT
sudo iptables-save

Automatically start MongoDB on server Boot:

To start MongoDB automatically on server boot, you must run the following commands

CentOS 6.4
sudo chkconfig mongod on

sudo update-rc.d mongod defaults

You can install MongoDB in both VPS and Dedicated Servers Provided by TNP HOST

Was this post helpful?

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.