Make an empty file of e.g. 2GB (must be root or use sudo):
# dd if=/dev/zero of=/swapfile bs=1024 count=2097152
OR
# fallocate -l 1G /swapfile
Set it to only be readable by root (because memory can contain anything, including sensitive data):
# chmod 600 /swapfile
Format it for swap usage:
# mkswap /swapfile
Enable it in /etc/fstab (skip this if you already had swap on /swapfile):
# echo ‘/swapfile none swap sw 0 0’ >> /etc/fstab
Turn it on:
# swapon -a
If you already have swap on /swapfile, do the following first:
# swapoff -a
# rm /swapfile