If your system is facing issues like system running out of memory frequently and you don’t want to increase physical memory. Then this is the best idea to add Swap memory on your system. Remember, swap memory is good but much slower than physical memory. This tutorial will help you to create a swap file on the Linux system and use it as swap memory.

How to Create Swap in Linux

Here is the step by step tutorial to create a swap file on the Linux machine and configure in the system.

Disable Swap

If you don’t need a swap file or need to increase swap file. You can disable an already active swap file on the system using the following command. Alternatively use free or top command to view swap memory status. My system have 2 GB physical memory installed. So I am creating a swap file of 4 GB using following command. Then set the proper permission on file: Now, again check that swap is enabled or not. You will see results something like below. Edit /etc/sysctl.conf file and append following configuration in file. Now reload the sysctl configuration file You can create a new larger swap file using the above steps or to disable permanently remove the entry from /etc/fstab file.

Conclusion

You have successfully created a swap file on your Linux machine and configured it as swap memory.