Nearly 4GB of RAM are used by the compilation process. If you only have 2GB, with 2GB swap, for example, the compile process may only complete in a minimal desktop-environment such as Fluxbox.
You can attempt running our system bootstrapping script to install all system dependencies:
wget --no-check-certificate https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py && python bootstrap.py
If this works, great! If not, see the appropriate section below. If you encounter an error, consider filing a bug saying that the bootstrapper didn't work. Please include output and relevant operating system details.
If you have already checked out the source code via Mercurial or Git you can also use mach with the bootstrap command:
Common Bootstrapper Failures
wget: command not found
If you see the above, you don't have wget installed. Try curl:
curl https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py > bootstrap.py && python bootstrap.py
If you don't have curl, download the file in your browser and run it by hand:
The above bootstrap scripts supports popular Linux distributions. If it doesn't work for you, see Linux build prerequisites for more.
The above bootstrap script should work on OS X 10.6 and newer. (As of at least 10.8, wget isn't included in a stock OS install but curl is.) If it doesn't, see Mac OS X build prerequisites.
Now you are ready to get the Firefox source and build, continue on from Simple Firefox build (Get_the_source).