1. create a 1G file for the swap.
sudo fallocate -l 1G /swapfile
we can verify that the correct amount of space was reserved by typing:
ls -lh /swapfile
2. Enabling the Swap File.
1.Make the file only accessible by typing:
sudo chmod 600 /swapfile.
2.Make the file as swap space by typing:
sudo mkswap /swapfile
3.Enabling the swap file and allow our system to start utilizing it .
sudo swapon /swapfile.
4.Now you can find that the swap space was added by typing:
free -h / (sudo swapon --show)
3. Delete the Swap File.
1.Disabling the swap file
sudo swapoff /swapfile
2.Remove the swap file
sudo rm -rf /swapfile