Follow this steps to configure swap file on linux:
If you wish to increase an existing swap file, please refer to this article: Increase Linux Swap File
1.Create the swapfile
sudo dd if=/dev/zero of=/swapfile bs=1024 count=4048576
2. Set file permissions
sudo chmod 600 /swapfile
3. Configure the file as a linux swap file
sudo chmod 600 /swapfile
4. Enable the swap file
sudo swapon /swapfile
5. Make the change peristent.
Edit the following file:
/etc/fstab
Append the following line:
/swapfile swap swap defaults 0 0
6. Check swap was activated
sudo swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 3.9G 87.6M -1