I follow the following steps to create a swap-file.
# Create the swap file
sudo fallocate -l 11G /swapfile
I have 8GB RAM on my system, so I choose to have 11GB of swap. This is enough to allow me to hibernate if I want to.
# Only root should be able to read this file
sudo chmod 600 /swapfile
# Set the file as the swap area
sudo mkswap /swapfile
# Enable the swap
sudo swapon /swapfile
/etc/fstab
# in /etc/fstab
/swapfile swap swap defaults 0 0
sudo swapon --show