How to install firefox in Amazon Cloud (AWS EC2)?

Executing below commands solved the problem:

sudo apt-get install xvfb

sudo Xvfb :10 -ac

export DISPLAY=:10

sudo firefox

You can install Xvfb (X virtual framebuffer, virtual Linux display system) and Firefox.

For Ubuntu server:

sudo apt-get install xvfb firefox

And then run your app via:

xvfb-run <your-app>

There are lot of tutorials how to run Firefox in headless mode. Just search for headless firefox ubuntu. One of good resource is: http://elementalselenium.com/tips/38-headless. In there, there are some options how to run your app under xvfb.