Create a swap file

fallocate -l 4G /var/swapfile1

Change permissions

chown root:root /var/swapfile1
chmod 0600 /var/swapfile1

Format the file

mkswap /var/swapfile1

Enable the swap file

swapon /var/swapfile1

Add the swap file to fstab

Open the fstab file

vim /etc/fstab

Add the following line

/var/swapfile1 none swap sw 0 0