How do I increase the size of swapfile without removing it in the terminal?
First disable swap file:
sudo swapoff /swapfile
Now let's increase the size of swap file:
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 oflag=append conv=notrunc
The above command will append 1GiB of zero bytes at the end of your swap file.
Setup the file as a "swap file":
sudo mkswap /swapfile
enable swaping:
sudo swapon /swapfile
You should add a new swapfile instead of resizing the exist one because it costs you nothing to do so. To resize a swapfile, you must first disable it, which evicts the swap contents to RAM, which increases pressure on RAM and may even summon the OOM killer (not to mention that you could possibly be thrashing your disks for several minutes). Multiple swap files are not a problem, it's trivially easy to setup yet another swap file. There's quite literally no benefit to resizing a swap file over adding another.
dd if=/dev/zero of=/some/file count=1K bs=1M
mkswap /some/file
sudo chown root:root /some/file
sudo chmod 600 /some/file
sudo swapon /some/file