This script allows you to easily create and configure swap memory on your Linux VPS (ideal for low-RAM servers like those with 1GB RAM). It interactively guides you through the process and applies sensible defaults if you just press Enter
.
You can run this script in one line directly from your terminal:
bash <(curl -Ls https://raw.githubusercontent.com/iamhelitha/swap-file-setup/main/install.sh)
- Interactive terminal prompts with default options
- Auto-creates and enables a swap file
- Configures swappiness and cache pressure
- Works with
fallocate
or falls back todd
- Permanently persists settings across reboots
- Detects and updates existing swap files if requested
- Ubuntu (16.04 and above)
- Debian (9 and above)
- Other systemd-based Linux distributions (may require minor tweaks)
β οΈ Not tested on CentOS, Fedora, or Alpine β feel free to open issues if you'd like support added!
- Checks if swap is already enabled and offers to update it
- Asks for the desired swap size (e.g.
1G
,512M
) β defaults to1G
- Creates a swap file and enables it
- Configures
vm.swappiness
andvm.vfs_cache_pressure
- Adds swap file to
/etc/fstab
for persistence - Shows memory status at the end
==============================
SWAP FILE SETUP FOR VPS
==============================
Enter swap size (e.g., 1G, 512M) [default: 1G]:
[*] Creating a 1G swap file at /swapfile...
[β] Swap successfully enabled with 1G
Swap helps extend available memory when RAM is full β crucial on small VPS servers where running MySQL, Apache, Node, or other services can cause memory pressure.
MIT License. Use freely and modify as needed.