To create a swap file on Ubuntu 24.04, follow these steps:
Step 1 : First, check the available memory using the command:
Step 2 : Next, check disk space using:
Step 3 : Allocate space for the swap file (e.g., 2GB) using:
Step 4 : Set proper permissions for the swap file:
Step 5 : Make the allocated file a swap area:
Step 6 : Enable the swap file:
Step 7 : Verify that the swap is enabled by running:
Step 8 : To make the swap file permanent across reboots, add the following line to /etc/fstab
:
Congratulations! You have successfully created a swap file on Ubuntu 24.04.