Get a VPS now!

InfrawireInfrawire LogoDocumentation
Appeler

Configure swap on a Linux VPS

On a low-RAM VPS, swap reduces out-of-memory kills. This guide adds a swap file.

📋 Prerequisites

  • Linux VPS with root/sudo
  • Free disk space (e.g. 2 GB for a 2 GB swap file)

Check RAM and current swap

Bash
free -h swapon --show

Create a 2 GB swap file

Bash
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile

Enable on boot

Bash
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Tune swappiness (optional)

10–30 is often better for VPS:

Bash
echo 'vm.swappiness=20' | sudo tee /etc/sysctl.d/99-swappiness.conf sudo sysctl -p /etc/sysctl.d/99-swappiness.conf

More stable server! 🚀