Deploying MongoDB on Ubuntu 14.04 with Vagrant

Vagrant MongoDB

One of the biggest problems when starting a new project is deploy the development environment on developers local computers or in some development or testing environment. Also, the problem increases when the developers must prepare their own development environments themselves. This self-build environments could be widely far from the final configurations that will be deployed on Quality, Pre-Production or Production environments, causing the famous “works on my machine”

All this is further complicated when the project has several components: web servers, load balancers, caching services, databases, etc…

Luckily there are several tools that help us with this kind of problems and through which the human error is greatly reduced.


One of these tools is Vagrant, a system that allows us to create and move development environments from one machine to another easily, regardless of the operating system. Vagrant abstracts the virtualization  system and allows us to install the desired software through automated systems such as Chef, Puppet or Shell Scripting software.

Let’s go!

In this and next articles, we’ll try to give a review of this tool and how to leverage its power for our development environments based MongoDB in which we can often find complex configurations.

In this first post we are going to deploy a simple environment, consisting of the following components:

  • Ubuntu 14.04 (64 bits) operative System
  • MongoDB 2.6 Stand Alone Database

Therefore our friend Pedro Amador, Infrastructure Director at Gigigo Group, will help us through the following tutorial based on a GitHub repository where you’ll find the entire solution.

GitHub Repository: Vagrant :: Ubuntu 14.04 64 bits + MongoDB 2.6:

Although in this post is about Ubuntu, Pedro also facilitates the installation with CentOS 6.5, which we’ll cover in a future post:

Initial Requirements

  • Git 1.7+ (if not installed use sudo apt-get install git)
  • Vagrant v1.6.5 + ( (if not installed use sudo apt-get install vagrant)
  • Virtualbox v4.3.16 + ( (if not installed use sudo apt-get install virtualbox)

In this case Vagrant uses Virtualbox as virtualization system to configure the machines that wake up the environment.

Step 1: Clone the repository and submodules

Step 2: Create and configure guest VM

 Step 3: Access the VM

Through the command  vagrant ssh you can access the guest VM shell

And then execute MongoDB Shell that is installed

Once you access with vagrant ssh you’ll access directly logged in with the “vagrant” user but you can upgrade your role to root through the command sudo -i or execute any command with the sudo prefix.

Ok but… Where is the magic?!

Wonderful, right?

Now let’s stop and see what has happened in reality, analyzing the Vagrantfile file in the root of the repository.

First you’ll find the private network definition and MongoDB default port forward from local machine to guest VM. With this hack we can expose MongoDB service inside our local network.

In the following lines there are some specifications abut the virtualization provider (in this case VirtualBox), and other system information (CPUs, RAM…)

Before proceed with the installation of the Linux Packages we must update the system.

Just to finish, Vagrant will invoke Puppet to provision the puppet files defined on the /manifest folder.

Puppet will do the rest of the work, installing MongoDB client and server from the last available version.


With a few lines of code, we have found quick way to have an environment to work on our application based on MongoDB, and a portable and replicable environment on any other machine or server.

This time we have only presented an introduction to the great advantages of working with this philosophy. In the following articles we’ll show more complex case involving specific configurations of MongoDB Replica Sets, Sharding and more!

César Trigo

Backend Development Director @ Gigigo Group

You may also like...

3 Responses

  1. September 21, 2015

    […] Let’s read someone else’s work on Mongodb on Vagrant box. […]

  2. November 28, 2015

    […] Deploying MongoDB on Ubuntu 14.04 with Vagrant […]

  3. November 28, 2015

    […] Deploying MongoDB on Ubuntu 14.04 with Vagrant […]

Leave a Reply