In this tutorial we will cover the steps needed to install MongoDB on your CentOS 6.4, Debian or Ubuntu platform.

Requirements

  • CentOS 6.4, Debian or Ubuntu installed on your computer/server
  • SSH access (Command line access to the server)
  • root privileges
  • Basic skills for working on a Linux environment

MongoDB is a NoSQL open-source document database written in C++. Its structure differs from the standard table-based relational one using JSON-like documents with dynamic schemas. In certain applications this allows easier and faster data manipulation.

Install MongoDB

We will use the default package manager included inside the corresponding Linux distribution:

CentOS 6.4

In order to install MongoDB with yum we will first add the epel repository to the system:

After that we can start the installation:

Debian/Ubuntu

First we will add the 10gen repository to the system:

Ubuntu

Debian:

After that we can start the installation:

You will be prompted to confirm the installation. During the process additional packages required by the Memcache service can be installed as well.

In CentOS we will need to start the service manually after the installation:

although in Debian/Ubuntu the system starts up the service automatically.

Test the functionality of the MongoDB service

The default MongoDB port is 27017. However the port as well as some other options can be changed inside the configuration file:

After any changes made to the MongoDB configuration file make sure to restart the service:

You can connect to MongoDB using the command line in order to check its functionality:

The command prompt will be changed to “>” and you can test some of the available commands. Type “help” inside the MongoDB terminal for full command list.

In order to be able to access the MongoDB server from remote computer you should make sure that the default port 27017 is allowed inside the server's firewall:

Start Up MongoDB automatically on server boot

In order for the service to start automatically upon server boot up you can execute the following command:

CentOS 6.4

Debian/Ubuntu