We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install a MEAN.JS Stack on an Ubuntu 14.04 Server

PostedNovember 26, 2014 69.4k views MEAN MongoDB Node.js Ubuntu


MEAN.JS is a full-stack JavaScript development solution that pulls together some of the best JavaScript technologies so that you can get applications into production quickly and easily. MEAN.JS consists of MongoDB, ExpressJS, AngularJS, and Node.

In this guide, we will install each of these components onto an Ubuntu 14.04 server. This will give us the applications and structure we need to create and deploy MEAN apps easily.


To begin this guide, you will need to have access to an Ubuntu 14.04 server.

You will need a non-root user account with sudo privileges to correctly install and configure the components we will be working with. Follow our Ubuntu 14.04 initial server setup guide to set up an account of this type.

When you are finished with the initial configuration of your server, log in with your non-root user and continue with this guide.

Download and Install MongoDB and Dependencies through Apt

Throughout this guide, we will be installing software using a number of different techniques depending on each project's requirements. The first set of installations will use apt, Ubuntu's package management system.

Before we can begin installing software, we will be adding an additional repository with up-to-date MongoDB packages. This repository is provided by the MongoDB project itself, so it should always have recent, stable versions of MongoDB.

First, we must add the MongoDB team's key to our system's list of trusted keys. This will allow us to confirm that the packages are genuine. The following command will add the correct key to our list (if you wish, you can verify the key ID through MongoDB's official documentation):

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Now that we trust packages signed by the MongoDB maintainers, we need to add a reference to the actual repository to our apt configuration. We can create a separate file that will be sourced by apt with the correct repository reference by typing:

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

Our system is now configured with the new MongoDB repository. We can update our system's local package cache so that it knows about the new packages, and then we can install the software we need.

We will be installing MongoDB packages to use as our database, git to help us with later installations, and some packages that we will need as dependencies and build dependencies for Node:

sudo apt-get update
sudo apt-get install mongodb-org git build-essential openssl libssl-dev pkg-config

Once the installation is complete, we can move on to building Node.

Download, Build, and Install Node from Source

Node is a very fast-moving project that cuts releases frequently. In order to get an up-to-date copy of Node, built to run on our specific system, we will be downloading the most recent source and compiling the binary manually. This is a rather straight forward procedure.

First go to the download section of the Node website. In the main section of the page, there are download links separated by operating system, as well as a link for the source code in the upper-right corner of the downloads:

Node source code link

Right-click on the source code link and select "Copy link address" or whatever similar option your browser provides.

Back on your server, move into your home directory and use the wget command to download the source code from the link you just copied. Your Node source URL will likely be different from the one shown below:

cd ~
wget http://nodejs.org/dist/v0.10.33/node-v0.10.33.tar.gz

Once the file has been download, extract the archive using the tar command:

tar xzvf node-v*

This will create the directory structure that contains the source code. Move into the new directory:

cd node-v*

Since we already installed all of the Node dependencies using apt in the last section, we can begin building the software right away. Configure and build the software using these commands:


Once the software is compiled, we can install it onto our system by typing:

sudo make install

Node is now installed on our system (along with some helper apps). Before we continue, we can get rid of both the source code archive and the source directory to keep our system clean:

cd ~
rm -rf ~/node-v*

Install the Rest of the Components with NPM, Git, and Bower

Now that we have Node installed, we have access to the npm package manager, which we can use to install some of the other software we require.

MEAN.JS uses a separate package manager, called bower, to manage front-end application packages. It also uses the Grunt Task Runner to automate common tasks. Since these are management packages that should be available to assist us with every app we create, we should tell npm that we need these globally installed:

sudo npm install -g bower grunt-cli

Now, we finally have all of the prerequisite packages installed. We can move onto installing the actual MEAN.JS boilerplate used to create applications. We will clone the official GitHub repository into a directory at /opt/mean in order to get the most up-to-date version of the project:

sudo git clone https://github.com/meanjs/mean.git /opt/mean

Enter the directory and tell npm to install all of the packages the project references. We need to use sudo since we are in a system directory:

cd /opt/mean
sudo npm install

Finally, since we are operating in a system directory, we need to call bower with sudo and the --allow-root option in order to install and configure our front-end packages:

sudo bower --allow-root --config.interactive=false install

See the Results

MEAN.JS is now completely installed. We can start up the sample application using the Grunt Task Runner within our project directory. This will run the application and allow it to begin accepting requests:

cd /opt/mean

Once the process starts, you can visit your server's domain name or IP address in your web browser on port "3000":


You should see the sample MEAN.JS application:

MEAN.JS sample application


Now that you have the necessary components and the MEAN.JS boilerplate, you can begin making and deploying your own apps. Check out the documentation on MEAN.JS website for specific help on working with MEAN.JS.

After you get your application up and running, you'll probably want to configure a reverse proxy to your application server in order to feed your app connections. We will cover this in a later guide.


Creative Commons License