Memory management on VPS
Practical commands for checking memory, disk, and package health on a Linux cloud server (tested on Ubuntu 22.04).
Free Memory on Virtual Private Server (VPS)
1. Quick overview
free -h
Look at the available column. It shows memory that can be used without swapping, and it matters more than the free column.
2. Disk space
Low disk space often shows up together with low memory.
df -h /
sudo du -xhd1 /var 2>/dev/null
sudo journalctl --disk-usage
df -h /shows total, used, and free space on the main disk.du -xhd1 /varshows which folders under/varuse the most space.journalctl --disk-usageshows how much space system logs take.
3. Swap status
swapon --show
No output means no swap is active.
4. Processes by memory use
ps aux --sort=-%mem | head -n 10
Shows the top 10 processes by memory use.
5. Detailed memory info
head -n 5 /proc/meminfo
vmstat 1 5
/proc/meminfoshows total, free, and available memory in detail.vmstat 1 5prints 5 snapshots, one per second. Watch thesiandsocolumns: values above zero mean the system is swapping.
6. Live view
top
Press M to sort by memory and q to quit.
7. Stuck package processes
ps aux | grep -E "apt|dpkg"
sudo dpkg --audit
- The first command lists running package processes.
dpkg --auditreports packages that are half-installed or misconfigured. No output means everything is fine.
!!! Warning
Do not kill package processes or delete lock files until you know what they are.