Add a swap file:
Create a file (you can replace /swapfile with another location and filename): sudo fallocate -l 1G /swapfile
Change its permissions: sudo chmod 600 /swapfile
Mark the new file as swap space: sudo mkswap /swapfile
Enable the swap file: sudo swapon /swapfile
Check and see if the file is enabled: swapon --show
Update fstab to make your changes permanent (you might want to create a backup of the existing fstab): echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Adjust swappiness, if needed: