Add swap space for Linux

Reference document:

If you use a server with smaller memory, you can add a swap space for it.

  1. execute sudo swapon --show, if there already exist swap file, you need delete it as following:

    1
    2
    
    sudo swapoff $swapfile
    sudo rm $swapfile
    
  2. sudo dd if=/dev/zero of=$swapfile bs=1M count=8192

  3. sudo chmod 600 $swapfile

  4. sudo mkswap $swapfile

  5. sudo swapon $swapfile

Now you can execute sudo swapon --show or free -m to ensure it.