Add a swapfile

How to add a Swapfile on your VPS:

Bild von Free-Photos auf Pixabay

Run these commands to make a swapfile (for small VPS under 2GB RAM) :

sudo dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
sudo mkswap /var/swap.img
sudo swapon /var/swap.img

Run free again to confirm you now have a swapfile.
Note: If you chose a different server option from Vultr / Digital Ocean, with less RAM,
you’ll need a LARGER swapfile, i.e. set the count parameter to something
larger like 2048, 4096 etc.
If the compilation steps fails partway through this is usually the reason.

To make the swap file persist when the server is rebooted:

sudo chmod 0600 /var/swap.img
sudo chown root:root /var/swap.img
sudo nano /etc/fstab

Append the following line to the end of the file:

/var/swap.img none swap sw 0 0

Save the file and exit

Leave a Reply

Your email address will not be published. Required fields are marked *