Enable swap on my Gen 4 VPS & Dedicated Server
Swap on a server provides additional virtual memory when physical RAM is exhausted. It allows the system to temporarily store data on disk, preventing crashes or slowdowns due to memory limitations and ensuring smooth operation of applications. Swap can be enabled on your server through SSH.
- Connect to your server using SSH.
- Switch to the root user.
- Create a file that will be used for swap:
sudo fallocate -l 1G /swapfile
- Set the permissions for the file:
sudo chmod 600 /swapfile
- Set up a Linux swap area on the file:
sudo mkswap /swapfile
- Enable swap:
sudo swapon /swapfile
- Using your preferred text editor command, open your
/etc/fstabfile, append the following line of code, and then save your changes:
/swapfile swap swap defaults 0 0
- Verify that swap is active:
sudo swapon --show
An output similar to the following will verify that swap is enabled:
NAME TYPE SIZE USED PRIO /swapfile file 1024M 0B -2