DEV Community

Mohan Upadhyay for The Coders Blog

Posted on • Originally published at thecodersblog.com on

3

How to enable swap in ubuntu and debian?

What is swap space?

Swap space in any operating system is amount of disk space reserve for moving inactive pages from RAM. Swap space are of two type dedicate swap or of swap files in linux OS. Here we will create a swap file for the linux system.

We assume that the system does have not swap partition for this guide.

Check if your system already exist swap partition.

Open the terminal, and enter the following command to check.

swapon --show
Enter fullscreen mode Exit fullscreen mode
Check free memory and disk.
free h
 //or
 df -h
Enter fullscreen mode Exit fullscreen mode

If you have sufficient space in you hard-disk then lets continue.

Step:1 Make swap off
swapoff /var/swapfile
Enter fullscreen mode Exit fullscreen mode
Step 2: Resize the swapfile

Here let us increase to 2GB (assuming existing one has 1GB space as given in the article)

dd if=/dev/zero of=/var/swapfile bs=1024k count=2000
Enter fullscreen mode Exit fullscreen mode
Step 3: Make swapfile usable
mkswap /var/swapfile
Enter fullscreen mode Exit fullscreen mode
Step 4: Make swapon
swapon /var/swapfile
Enter fullscreen mode Exit fullscreen mode
Step 5: Change permission to 0600
chmod 0600 /var/swapfile
Enter fullscreen mode Exit fullscreen mode
Step 6: Verify the swapfile
swapon -show
Enter fullscreen mode Exit fullscreen mode
Step 7: Make swap file permanent
echo '/var/swapfile none swap sw 0 0' | tee -a /etc/fstab
Enter fullscreen mode Exit fullscreen mode

Heroku

The AI PaaS for deploying, managing, and scaling apps.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Get Started

Top comments (0)

Learn How Clay Overcame Web Scraping Barriers

Learn How Clay Overcame Web Scraping Barriers

Clay helps customers enrich their sales pipeline with data from even the most protected sites. Discover how Clay overcame initial limitations and scaled past data extraction bottlenecks with a boost from ZenRows.

Read More

👋 Kindness is contagious

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay