How to add 8 gb swap file instead of the 1 gb swap partition created by Xubuntu Linux on install

When using Android Studio or any other disk intensive applications, on Ubuntu-based distros, it is difficult to squeeze performance due to less RAM. 8gb RAM if using Android Studio and if Firefox web browser is also being used, the system will freeze or hang. To prevent this, increase the swap size.

Unfortunately, Ubuntu-based distros only create a 1 gb swap partition and if using full disk encryption, there is not much that can be done to intervene and change the swap partition size to 8gb.

The way forward is not to use the swap partition of 1 gb and create a swap file of 8gb. To do so, open a terminal window and enter the following commands:

Check the swap partition and where swap is being used.
$ cat /proc/partitions <enter>
$ sudo swapon --show <enter>

Set up a 8 gb swap file in a folder named sw
$ sudo mkdir /sw <enter>
$ sudo fallocate -l 8G /sw/swapfile <enter>
$ sudo chmod 600 /sw/swapfile <enter>
$ sudo mkswap /sw/swapfile <enter>

Do the following in the /etc/fstab file:
$ sudo vi /etc/fstab <enter>
#/dev/mapper/vgxubuntu-swap_1 none swap sw 0 0 #Put a hash to disable the swap partition
/sw/swapfile swap swap defaults 0 0 #Add this line to enable swap file

Enable the swap file

$ sudo swapon /sw/swapfile <enter>
$ sudo swapon --show <enter>

Now the swap file of 8 gb should be active.