HOWTO: Free Disk Space For An Apt Update

Ubuntu LogoI try to limit the space available to my root partition, but sometimes that comes back to bite me in the ass. Especially if I haven’t updated in a while. The major problem with using binary package managers is that they need space for the downloaded tar.gz files AND the space to extract it. There are some tricks you can do to help free up some space for package upgrades.

  • UPDATE A SUBSET. If you get a screen-full of packages that need to be updated and you don’t have the disk space to do it all at once, you can install a subset by using sudo apt-get install [space-separated-package-list]. I usually go for at least two lines worth of packages at a time, skipping over big ones like mysql and linux kernel files.
  • REMOVE THE OLD PACKAGE(S) FIRST. MySQL and the linux kernel files are quite big packages when your disk space is measured in megabytes. They’ll want well over 100MB each. A good trick is to remove the packages first. For MySQL, simply use the package names that sudo apt-get upgrade gives you. For the kernel, you need to specify:
     

    • linux-image-x.x.xx-xx-[generic|server]
    • linux-restricted-modules-x.x.xx-xx-[generic|server]
    • linux-ubuntu-modules-x.x.xx-xx-[generic|server]

    You can find out what what kernel you currently have by typing ls /lib/modules at the console. Unless you’ve manually deleted the files, there will be a directory for each kernel you have installed. It’s safe to delete kernels on a running system as long as you get another working kernel installed before reboot.

  • CLEAR OUT APT’S CACHE. By default, apt keeps a copy of everything you’ve upgraded and installed since the system was first installed. Clearing out the cache by using sudo rm /var/cache/apt/archives/* and sudo rm /var/cache/apt/archives/partial/* can clear out a good bit of disk space.
  • REDUCE APT’S LIST SPACE. Apt keeps a copy of the package lists in /var/lib/apt/lists. You can clear out some space by deleting these files using sudo rm /var/lib/apt/lists/*, editing the /etc/apt/sources.list file to exclude lines with deb-src, universe, and multiverse, and then running sudo apt-get update. You can re-enable the repositories again after the update.
Advertisements