To create a swap file on Ubuntu 22.04, follow these steps:
Step 1 : Use the following command to check the available disk space:
Step 2 : Use the following command to create a swap file of the desired size. For example, to create a 2 GB swap file, you can use the following command:
Step 3 :Use the following command to change the permissions of the swap file:
Step 4 :Use the following command to mark the file as a swap file:
Step 5 :Use the following command to enable the swap file:
Step 6 :Verify that the swap file is enabled using the following command:
Step 7 :To make the swap file persistent across reboots, add the following line to the /etc/fstab
file:
The recommended size for a swap file is equal to the amount of RAM in the system, or 2-4 GB. However, the actual size depends on the specific use case and the amount of memory in the system.