How to Fix “Insufficient Space in /var/cache/yum” Error on CentOS: A Sysadmin’s Guide


2 views

When working with legacy CentOS systems (particularly CentOS 5 in this case), you might encounter the frustrating disk space error in YUM's cache directory. The key indicators are:

Error Downloading Packages:
  14:libpcap-0.9.4-15.el5.i386: Insufficient space in /var/cache/yum/base/packages
    * free   0 
    * needed 108 k

The df -h output reveals the root cause:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              20G   19G     0 100% /

Our root partition is completely full, specifically affecting /var which resides on /dev/sda1. Note that while /home has plenty of space (154G free), it's on a separate partition (/dev/sda3).

Here are actionable solutions to clear space:

1. Clean YUM cache more thoroughly:

yum clean all
rm -rf /var/cache/yum

2. Remove old kernel versions (common space hog):

package-cleanup --oldkernels --count=1

3. Clear system logs (carefully):

journalctl --vacuum-size=50M
rm -rf /var/log/*-????????

For permanent resolution, consider these approaches:

Option A: Extend the root partition
Using growpart and resize2fs if you have unallocated space.

Option B: Move YUM cache to another location

mkdir /home/yumcache
sed -i 's|^cachedir=.*|cachedir=/home/yumcache|' /etc/yum.conf

If you urgently need libpcap while fixing the space issue:

wget http://vault.centos.org/5.11/os/i386/CentOS/libpcap-0.9.4-15.el5.i386.rpm
rpm -ivh libpcap-0.9.4-15.el5.i386.rpm --nodeps
  • Set up monitoring for partition usage
  • Configure log rotation policies
  • Regularly clean package caches via cron

When your root partition (/dev/sda1) shows 100% usage in df -h, yum operations will fail with the "Insufficient space" error, even if other partitions have plenty of space. This occurs because yum defaults to using /var/cache/yum for downloads, which resides on the root partition.

Try these commands to quickly free up space:

# Remove cached packages
sudo yum clean packages

# Remove old kernel versions (keep at least 2)
sudo package-cleanup --oldkernels --count=2

# Clean up orphaned packages
sudo package-cleanup --orphans

# Remove cached data from all enabled repos
sudo yum clean all

For systems with separate partitions like your /home, we can reconfigure yum:

# Create new cache directory
sudo mkdir -p /home/yumcache

# Edit yum configuration
sudo vi /etc/yum.conf

Add or modify these lines:

[main]
cachedir=/home/yumcache
keepcache=1
debuglevel=2

For one-time installations, use the --downloaddir flag:

sudo yum install --downloaddir=/home/tmp libpcap

Then manually install with:

sudo rpm -ivh /home/tmp/libpcap-*.rpm

If you consistently face space issues, consider resizing partitions. For LVM systems:

# Extend root logical volume
sudo lvextend -L+10G /dev/centos/root
sudo xfs_growfs /

Create a maintenance script (/usr/local/bin/yum-clean):

#!/bin/bash
# Clean yum cache
yum clean all &> /dev/null

# Remove old logs
find /var/log -type f -name "*.gz" -delete
find /var/log -type f -mtime +30 -delete

# Clean tmp
rm -rf /tmp/*

Make it executable:

sudo chmod +x /usr/local/bin/yum-clean

Install and configure ncdu for better disk usage analysis:

sudo yum install ncdu
ncdu /

This will help identify large files that can be safely removed.