Simple Installation of Node.js and MongoDB

So you have got your AWS EC2 Amazon Linux instance running. You connected with ssh and everything looks like the old familiar territory. Now you have heard about all these wonderful technologies called Node.js, MongoDB, real-time web applications, Express.js, and what have you. There are gazillions of installation scripts and Stack Overflows in Google, but go figure.

I have distilled installation scripts that were tested to work.

Note that Amazon Linux is essentially the CentOS Linux distribution.


Run the installation script with:
sudo ./

 # required gcc and g++
 yum install gcc
 yum install gcc-c++ compat-gcc-32 compat-gcc-32-c++

 echo 'export PATH=/local/bin:$PATH' >> ~/.bashrc
 . ~/.bashrc
 mkdir node-latest
 cd node-latest
 curl | tar xz --strip-components=1
 make install

This also installs NPM - the Node.js package manager.


To install MongoDB you first need to add a repository to yum, the Linux package manager. Create the file:


   name=10gen Repository

Run the installation script with:
sudo ./

cat 10gen.repo > /etc/yum.repos.d/10gen.repo
yum install mongo-10gen mongo-10gen-server

MongoDB Configuration

The configuration is in /etc/mongod.conf. To edit,

 sudo vi /etc/mongod.conf

The defaults are alright for the start. You should consider changing two important things:

  • dbpath - where the database is stored
  • logpath - where the log file is stored

If you change any of these, you need to change the file owner of the chosen folder. So if your new dbpath is /home/johndoe/data, do:

 chown -R mongod:mongod /home/johndoe/data

Running MongoDB


 sudo service mongod start


 sudo service mongod stop