Normally a 2GB should be enough for swap on Ubuntu, the following commands will help you create that, but you can also make change to fit your need.
sudo swapoff -a # turn off current swap so it can be updated sudo fallocate -l 2G /swapfile # create a /swapfile of 2GB, if you want 16GB just change this number sudo chmod 600 /swapfile # change write permission sudo mkswap /swapfile # make the file as swap sudo swapon /swapfile # finally add it to swap config
Then you also need to edit this file
/etc/fstab as following for
/swapfile swap swap defaults 0 0