English

Configure swap on a Linux VPS

1 min
VPS/VDS Hosting

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! 🚀

Stay up to date with the latest offers, discounts and special promotions.

View promotions

We use cookies

We use analytics cookies to improve your experience on our site. No data is sold to third parties. Learn more in our privacy policy.