Gentoo - Portage Cleanup

This article gives some tips on saving disk space and keeping your emerge system tidy.

Cleaning up the System

Some packages may have been installed earlier that are no longer needed. We can see what these are by running:

sudo emerge --depclean -vp

The end of the output will look something like this:

>>> These are the packages that would be unmerged:

    selected: 6b-r8 
   protected: none 
     omitted: none 

    selected: 1.2.35 
   protected: none 
     omitted: none 

    selected: 4.1.2 
   protected: none 
     omitted: 4.3.2-r3 

>>> 'Selected' packages are slated for removal.
>>> 'Protected' and 'omitted' packages will not be removed.

Packages installed:   111
Packages in world:    6
Packages in system:   51
Required packages:    110
Number to remove:     3

The ‘Packages in world’ and ‘Packages in system’ are the packages that we’ve explicitly installed in the past; all the other packages are their dependencies. The ‘Number to remove’ are the packages that are installed that we didn’t explicitly ask for, and are not needed by the ones we did explicitly install.

Supposing we wanted to keep the ‘jpeg’ package, we could add it to the world set with:

sudo emerge --noreplace media-libs/jpeg

Now if we run the depclean again, that package will not show up in the list of packages to remove:

sudo emerge --depclean -vp

In our example, it will remove version 4.1.2 of gcc, but leave the newer version intact.

If we wanted to specifically keep the 4.1.2 version of gcc, we could run:

sudo emerge --noreplace =sys-devel/gcc-4.1.2

If you change your mind, you can just ‘–unmerge’ the package manually:

sudo emerge --unmerge =sys-devel/gcc-4.1.2

You can see which packages are in ‘world’ with:

sudo cat /var/lib/portage/world

Once we’re happy with the list of packages that will be removed, we can run the command without the -vp:

sudo emerge --depclean

Saving Space

One thing about Gentoo is that it likes to download and keep all the source files for every install it does. It usually stores these in ‘/usr/portage/distfiles’.

We can clean that up with the ‘eclean’ command:

sudo eclean -p distfiles

As with most Gentoo commands, the ‘-p’ is for ‘pretend’. Go through the list of files in the output and if you feel comfortable with those being deleted, you can go ahead and run without the ‘-p’.

Usually these files are not of too much consequence, and should you need to re-emerge something later, it should just download them again automatically.

By default, ‘eclean’ will only clean away source files for ebuilds that are no longer available in the portage tree. If you’re really low on disk space, you can use the ‘eclean’ command with the ‘–destructive’ flag. You can find out more about this with:

man eclean

To exit the man program you can hit ‘q’.


Want to comment?

(not made public)


(use plain text or Markdown syntax)