Create a Swap File
sudo fallocate -l 1G /swapfile
Enabling the Swap File
sudo chmod 600 /swapfile
sudo swapon /swapfile
Verify swap
free -h
Output
total used free shared buff/cache available
Mem: 488M 37M 96M 652K 354M 425M
Swap: 1.0G 0B 1.0G
Make the Swap File Permanent
Back up the /etc/fstab file in case anything goes wrong:
sudo cp /etc/fstab /etc/fstab.bak
Add the swap file information to the end of your /etc/fstab file by typing:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab