Create a temporary swap file on Debian/Ubuntu

Compiling Phusion Passenger on a low budget VPS,  you may run out of memory with a message like:

virtual memory exhausted: Cannot allocate memory

It is very easy to add a temporary swap file if you run out of memory:

sudo dd if=/dev/zero of=/tmpswap bs=1M count=1024 #1GB file
sudo mkswap /tmpswap
sudo swapon /tmpswap

To remove it when not needed anymore:

sudo swapoff /tmpswap
sudo rm /tmpswap

Leave a Reply