This method is learned from https://www.digitalocean.com/community/questions/how-to-change-swap-size-on-ubuntu-14-04:

(change count=1024 for the size you need)

sudo -s
swapoff -a
dd if=/dev/zero of=/swapfile bs=1M count=1024
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile