This article applies if you already have a swap file configured and you wish to increase it.
If swap file is not enabled on your system, refer to this article: Setup Linux Swap File
Follow this steps to increase the swap file on linux:
1.Deactivate swapfile first
sudo swapoff -v /swapfile
2. Delete swapfile and recreate it to the desired size
sudo rm /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1024 count=2048576
3. Enable the swap file
sudo swapon /swapfile
4. Check swap was activated
sudo swapon --show
The output should be similar to the following
NAME TYPE SIZE USED PRIO
/swapfile file 3.9G 87.6M -1