Your cart is currently empty!
How to Increase Swap Size on Ubuntu Linux
Running out of memory on your Ubuntu system? If your applications are sluggish or crashing under heavy load, it might be time to increase your swap space. Swap is the portion of disk used as virtual memory when RAM is full. It’s not a performance booster, but it can prevent crashes and keep things running when RAM is maxed out.
Here’s a no-nonsense guide to increasing swap size on Ubuntu.
Check Your Current Swap Setup
First, see how much swap you’re using:
swapon --showIf that returns nothing, you probably don’t have swap configured. You can confirm with:
free -hStep 1: Turn Off Existing Swap (If Needed)
If you’re increasing an existing swap file:
sudo swapoff /swapfileStep 2: Resize or Create a New Swap File
Option A: Resize Existing Swap File
Let’s say you want to increase it to 4GB:
sudo dd if=/dev/zero of=/swapfile bs=1G count=4Or if you already have a swap file and just want to resize it:
sudo truncate -s 4G /swapfileOption B: Create a New Swap File (if none exists)
sudo fallocate -l 4G /swapfileStep 3: Set Correct Permissions
sudo chmod 600 /swapfileStep 4: Format the Swap File
sudo mkswap /swapfileStep 5: Enable the Swap File
sudo swapon /swapfileTo confirm:
swapon --showStep 6: Make It Permanent
Edit the /etc/fstab file:
sudo nano /etc/fstabAdd this line if it’s not already there:
/swapfile none swap sw 0 0Save and exit.
Bonus: Adjust Swappiness (Optional)
Swappiness controls how aggressively Ubuntu uses swap. Default is 60. If you want it to favor RAM more, lower it:
sudo sysctl vm.swappiness=10To make it permanent:
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.confDone
That’s it. You’ve increased your swap space. This can be a lifesaver for servers, older machines, or systems doing heavy multitasking.
Have questions or want help tweaking your system? Drop them in the comments below.

Tech enthusiast and content creator passionate about making technology simple for everyone. I share practical tips, guides, and reviews on the latest in computers, software, and gadgets. Let’s explore the digital world together!
