yeah the ol memory is a real bitch on the pi...
did you do this:
sudo raspi-config - Advanced Options -> Memory Split -> set GPU memory to minimum (16MB)
??
if so then you will have to make a swap file. basic instructions for doing so
here though I strongly recommend trying the memory split first cause a swap file is going to slow compile down significantly.