Create swapfile
sudo install -o root -g root -m 0600 /dev/null /swapfile
Write out a 4GB file named ‘swapfile’
dd if=/dev/zero of=/swapfile bs=1k count=4096k
Let linux know about swap file
mkswap /swapfile
Activate swap
swapon /swapfile
activate swap also after boot. Add to the file system table
echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab