---
title: "How to set up swap on Ubuntu on a VPS | StreetHosting"
description: "A simple guide to setting up swap on an Ubuntu VPS, cutting out freezes caused by low memory and making your service more stable."
url: "https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps"
type: "page"
language: "en-US"
---

VPS · 2 min · Intermediate

Published on Jun 1, 2026 · Updated on Jun 1, 2026

# Set up swap on Ubuntu on a VPS

Swap does not replace RAM, but it helps during peaks and can keep services from crashing when memory runs out.

By [Equipe StreetHosting](https://streethosting.com.br/en/autores#equipe-streethosting) · StreetHosting infrastructure and support team

[Linux administration](https://streethosting.com.br/en/guides/topics/linux) [Hardware and datacenter](https://streethosting.com.br/en/guides/topics/hardware) [Getting started](https://streethosting.com.br/en/guides/topics/getting-started)

Summarize with:

[](https://chat.openai.com/?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "ChatGPT") [](https://claude.ai/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Claude") [](https://www.google.com/search?udm=50&aep=11&q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Google AI Mode") [](https://x.com/i/grok?text=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Grok") [](https://www.perplexity.ai/search/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Perplexity")

Share:

[](https://x.com/intent/tweet?text=How%20to%20set%20up%20swap%20on%20Ubuntu%20on%20a%20VPS&url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps "Share on X") [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps "Share on Facebook") [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps "Share on LinkedIn") [](https://wa.me/?text=How%20to%20set%20up%20swap%20on%20Ubuntu%20on%20a%20VPS%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Fset-up-swap-ubuntu-vps "Share on WhatsApp")

For agents: Copy as Markdown [.md](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps.md)

[Previous UFW on Ubuntu VPS: firewall rules without losing SSH](https://streethosting.com.br/en/guides/vps/ufw-firewall-ubuntu-vps)

In this guide 3 sections

* [When to use swap](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#quando-usar-swap)
* [Basic setup](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#configuracao-basica)
* [Limits and precautions](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#limites-e-cuidados)

Quick answer

Setting up **swap** on Ubuntu can keep your VPS from freezing during usage peaks. It works as backup memory on disk when the RAM fills up.

## When to use swap[](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#quando-usar-swap)

Swap is useful when the server's load varies and there is a risk of running out of memory. On lightweight applications, it acts as a safety net.

## Basic setup[](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#configuracao-basica)

1. Check the current memory and the average usage.
2. Create a swap file of the right size.
3. Enable the swap and set it to start at boot.
4. Run a load test and watch how it behaves.

After the setup, monitor real memory usage to decide whether to keep your current VPS or move up to a bigger plan.

## Limits and precautions[](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#limites-e-cuidados)

Swap helps keep the service online, but it does not fix a permanent capacity problem. If swap usage stays high all the time, it is a sign you are short on resources.

Do not use swap as an excuse to keep an undersized server for a long time. It usually increases latency and makes the experience worse.

To get better visibility and stability, pair it with [active monitoring](https://streethosting.com.br/en/guides/vps/uptime-kuma-vps-monitoring) and consider an upgrade to a [Ryzen VPS](https://streethosting.com.br/en/vps/ryzen).

In this guide

* [When to use swap](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#quando-usar-swap)
* [Basic setup](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#configuracao-basica)
* [Limits and precautions](https://streethosting.com.br/en/guides/vps/set-up-swap-ubuntu-vps#limites-e-cuidados)

## Frequently asked questions

Does swap make a VPS faster?

No. It improves stability during memory peaks, but it does not replace a RAM upgrade.

How much swap should I create?

It depends on your workload. In many cases, starting with a moderate size already helps.

Can I use swap on an SSD?

Yes, with some common sense. Avoid constant heavy writes without a reason.

Next step

See Ryzen VPS

Ryzen 9 9950X VPS in São Paulo with root access, NVMe and gamer Anti-DDoS.

[See Ryzen VPS](https://streethosting.com.br/en/vps/ryzen)

## Related guides

[VPS Beginner Ubuntu vs Debian for a VPS: which to choose in 2026 Ubuntu and Debian are both great choices for a VPS. The best one depends on your experience, your project and whether you value stability or convenience more. 2 min Read guide](https://streethosting.com.br/en/guides/vps/ubuntu-vs-debian-for-vps) [VPS Intermediate How to install Uptime Kuma on a VPS and monitor sites and ports Uptime Kuma checks sites, APIs, ports and scheduled jobs at set intervals and alerts you when something goes down. Here is how to install it with Docker, serve it over HTTPS, pick the right monitor type and turn on alerts. 8 min Read guide](https://streethosting.com.br/en/guides/vps/uptime-kuma-vps-monitoring) [VPS Intermediate How to secure SSH on a Linux VPS: keys, passwords, fail2ban SSH is usually the first target on any VPS with a public IP. This guide walks through a practical routine that cuts the risk without complicating your day: an ED25519 key, password-free login, admin access through sudo, blocking of automated attempts and a periodic review of authorized keys. 4 min Read guide](https://streethosting.com.br/en/guides/vps/secure-ssh-linux-vps)

[← Back to the Guide Center](https://streethosting.com.br/en/guides)
