# change 2G to how many GB of swap you want
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon -s
echo "/swapfile swap swap sw 0 0" >> /etc/fstab
Verify swap memory is added:
free -m
root@hostname:~# free -m total used free shared buff/cache available Mem: 985 194 268 0 522 644 Swap: 4095 0 4095