Emerge: How to prevent packages from being upgraded

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

This page aims to document various ways to prevent certain packages to be upgraded, and also the reasons why a user might want to prevent an upgrade, possibly offering a better solution to solve a given problem.

emerge --exclude

man emerge:

       --exclude ATOMS
              A space separated list of package names or slot atoms.
              Emerge won't install any ebuild or binary package that
              matches any of the given package atoms.

Note that in order for the command to be properly parsed within the shell environment, the the space separated list of packages must be provided within double quotes.

Example:

# emerge  --exclude "media-fonts/noto-cjk media-fonts/noto"  @preserved-rebuild

In this particular example, the two font packages are large and may take hours to download. The user wanted to temporarily skip those two package in order to rebuild the other ones without having to wait.

package.mask

A more permanent solution is to mask the packages within /etc/portage/package.mask/

world file

If you want to keep a specific version of a package, you might want to add it with its version number into the world file:

Part of /var/lib/portage/world

sys-kernel/gentoo-sources
sys-kernel/gentoo-sources:4.19.44
sys-kernel/gentoo-sources:4.9.76-r1

This way, it allows you to keep older versions of the kernel installed.