Ubuntu 24.04 is a powerful operating system, but sometimes your computer might run out of memory when running multiple applications. This can slow down your system and make it less efficient. In that case adding swap memory can help. Swap memory acts as an additional memory resource, allowing your computer to handle more tasks smoothly.

In this guide, we will show you how to easily add swap memory to your Ubuntu 24.04 system. The steps are simple and easy to follow, even for beginners.

Step-by-Step Guide to Adding Swap Memory on Ubuntu 24.04

Step 1: Check Existing Swap Memory

First, check if your system already has swap memory or not. Open the terminal and type:

sudo swapon --show

If no output is displayed, it means there is no swap memory configured.

How to Add Swap Memory on Ubuntu 24.04 Linux System Administration swap swap memory swapfile Ubuntu 24.04
Check Swap Memory Status

Step 2: Create a Swap File

Next, create a swap file. You can choose the size you need; Generally it is preferred to have swap size 1.5x or 2x of RAM size. My current system have 2GB Memory, so here we will create a 4GB swap file. Type the following command:

sudo fallocate -l 4G /swapfile

This command creates a file named “swapfile” with a size of 4GB.

How to Add Swap Memory on Ubuntu 24.04 Linux System Administration swap swap memory swapfile Ubuntu 24.04
Create Swapfile on Ubuntu 24.04

Step 3: Secure the Swap File

Set the correct permissions to secure the swap file:

sudo chmod 600 /swapfile

This ensures that only the root user can read and write to the swap file.

Step 4: Mark the File as Swap

Now, format the file as swap space by typing:

sudo mkswap /swapfile
How to Add Swap Memory on Ubuntu 24.04 Linux System Administration swap swap memory swapfile Ubuntu 24.04
Using mkswap to Make Swap Memory

Step 5: Enable the Swap File

Enable the swap file so that the system can start using it:

sudo swapon /swapfile

You can verify that the swap is active by running:

sudo swapon --show
How to Add Swap Memory on Ubuntu 24.04 Linux System Administration swap swap memory swapfile Ubuntu 24.04
Check Swap Memory Status after Creation

Step 6: Make the Swap File Permanent

To ensure that the swap file is used every time the system boots, add it to the fstab file:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
How to Add Swap Memory on Ubuntu 24.04 Linux System Administration swap swap memory swapfile Ubuntu 24.04
Update fstab for Swapfile on Ubuntu

Conclusion

Adding swap memory to your Ubuntu 24.04 system is a simple process that can greatly improve your computer’s performance. By following these easy steps, you can ensure that your system runs smoothly even when handling multiple tasks. Swap memory provides an extra cushion for your computer’s RAM, helping to prevent slowdowns and crashes. Enjoy a faster and more efficient Ubuntu experience!