From: https://unix.stackexchange.com/questions/294600/i-cant-enable-swap-space-on-centos-7
Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need
yum install nano -y
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo nano /etc/fstab
add this line:
/swapfile swap swap sw 0 0
run this command
sudo sysctl vm.swappiness=10
sudo nano /etc/sysctl.conf
add this line
vm.swappiness = 10
vm.vfs_cache_pressure = 50
To verify swap's size
swapon --summary
free -h