Programming Blog

Jeremy Morgan

Mostly Coherent Ramblings of a Silicon Forest Software Developer

How to Set Up the MEAN Stack on Digital Ocean

Author: Jeremy Morgan

If you haven’t heard of the MEAN stack, it’s a combination of technologies for serving up fast websites, using a set of technologies paired very well together. They consist of MongoDB, Express.JS, Angular.JS, and Node.JS. For more information check out MeanJS website for more details.

This is not to be confused with Mean.IO. This is also a MEAN stack, but the original creator forked it and started MeanJS instead. I find it to be less error prone and a bit more organized.

How to set up a MEAN stack on Digital Ocean.

Digital Ocean is one of the greatest services for a developer. You can spin up virtualized Linux servers for as little as $5 a month, and it’s a great cheap way to host your projects.

How to install MEAN Stack"

I know what some of you are thinking, “why not just press the MEAN app button on the console?”. This is a great way to set up a MEAN stack, but I am a firm believer in doing stuff like this manually. It’s important to know what you’re installing and how to do it, rather than rely on GUI tools for everything. You don’t really learn unless you do it.

That being said this article isn’t really specific to Digital Ocean, you can follow these steps on any Ubuntu machine. Digital Ocean just happens to be a good platform to try it on.

Get Started

To get started we’re going to create a droplet. For this tutorial I created an Ubuntu 14.04 x64 version.

The first thing you’ll want to do once you log in, is update it:

sudo apt-get update

And we’ll need to install Git, as it will be needed later.

sudo apt-get install git

Install Node.JS

Before we can install Node we’ll need some packages brought in:

sudo apt-get install python-software-properties python g++ make

Then we’ll add a new repo:

sudo add-apt-repository ppa:chris-lea/node.js

And update again.

sudo apt-get update
sudo apt-get install nodejs

Then we should update NPM:

npm install -g npm

And once that’s done we’ll install Bower and Grunt:

sudo npm i -g bower
sudo npm install -g grunt-cli

Install MongoDB

MongoDB will be the backend for the website. This is a relatively quick install, but must be done before the MEAN stack is installed.

First we need to import the public key:

sudo apt-key adv --keyserver hkp:// --recv 7F0CEB10

Then we need to create a list file for Mongo:

echo 'deb dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

Then run another update:

sudo apt-get update

And then we can install MongoDB:

sudo apt-get install -y mongodb-org

Now, check to see if MongoDB has started:

tail /var/log/mongodb/mongod.log

You should see this message:

How to install MEAN Stack"

And your MongoDB is up and running!

Install MEAN.JS stack

You’re almost done! This part is quick and easy. Just clone the latest repo into a folder (I used meanjs)

git clone meanjs

install it:

sudo npm install

and run it:


You’re done! You should see the following screen:

How to install MEAN Stack"

And just like that you’re ready to go.

If you want to run it as a full time server

When you run Grunt it starts your server, but as soon as you exit SSH it drops. Also NodeJS is a single threaded application so a single failure can bring down the service. This is why we use forever to run the server:

npm install forever

Now start it up:

forever start server.js

and you’ve got a full time server running.


I hope this helps illustrated the steps for getting a MEAN stack set up. This is just the beginning, in future tutorials we’ll build some stuff.

This stack is pretty awesome, and really important. I can definitely see this replacing PHP as a go-to quick web development technology for open source platforms. It’s advancing rapidly, offers incredible performance and reduced development time.

Do you like articles like this?

I’m constantly hacking on stuff and writing about happenings in the programmer world. You can subscribe to my feed here, or you can get the hacker newsletter 100% spam free!

You can also follow my projects on GitHub: