Swap space is a location on the system’s disk drive that is used when the system’s physical memory (RAM) is full. When this happens, pages in this system’s RAM that are inactive are moved to swap space to make room for active pages. You can either have a swap file or a dedicated swap partition on the system’s disk. If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use. Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices. If you don’t already have a swap file or want to create one, follow the steps below:

View Current Swapfile

To get started, first use the commands below to show your system’s current file swapfile settings. If you run the command above and the output is emptied, then your system doesn’t currently have a swapfile configured. A system with swap space enabled and configure should display similar lines as below: If your system does have a swapfile but wants to increase it, you can use the same steps below to increase it. First, turn off the current swapfile by running the commands below: After turning it off, go and remove its entry from the /etc/fstab file. Run the commands below to open the /etc/fstab file. Then comment out the highlighted line or remove it entirely. After that, save the file and exit. When you’re done, run the commands below to delete the current swap file from your system.

Create New Swapfile

Now that the system’s current swapfile is removed, run the commands below to create a new one. For this tutorial, we’re going to be creating a new swapfile of 2G space. To do that, run the commands below: Next, run the commands below to create a new swapfile. You should see similar output as below when successful: When you’re done, run the commands below to make sure only the root user can read and write to the swap file. Next, use Linux mkswap command utility to make that location on the disk a swapfile. You should then see a similar output as below: Finally, activate the swapfile by running the commands below: Next, go back to the /etc/fstab file and un-comment the line to enable the new swapfile or add a new line: Next, verify that the new swapfile is active by running the commands below: If everything is successful, you should see a new swapfile as below: That’s how one creates a new or increases a swapfile on Ubuntu Conclusion: This post shows you how to create or increase a swap file on Ubuntu 18.04 | 16.04 or other Linux systems. If you find any errors above, please use the comment form to report them. You may also like the post below: