How to enable swap space on Centos

Sometimes, if you run yum instal/update, you got failure about “Exiting on user cancel”. What? I didn't do that! That's may your memory limitation. So in this case, you will need to check your free memory by “free -h”, if you saw swap space is 0, that's for you. keep reading…

Create swap file

sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Enable in /etc/fstab

/swapfile   swap    swap    sw  0   0
Last modified: le 2018/11/16 11:16