Fix “command ‘gcc’ failed with exit status 4” Once Installing lxml

Today I’m installing sentry on my VPS, I’m using ubuntu 14.04 on smallest instance on DigitalOcean. But the installation failed because of sentry depend on lxml and the lxml failed to install through python pip. Here is the error stacktrace.

cc: internal compiler error: Killed (program cc1)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
    Compile failed: command 'gcc' failed with exit status 4
    cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitRJR8OE.c -o tmp/xmlXPathInitRJR8OE.o
    cc tmp/xmlXPathInitRJR8OE.o -lxml2 -o a.out
    error: command 'gcc' failed with exit status 4

I don’t know what exactly going on with this, but after looking up on¬†stackoverflow. Some answer told that this is memory problem, to fix this we just need to increase our memory by adding swapfile. Here is how to fix this.

sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Now I could install sentry without any trouble with this lxml issue.