Gentoo Linux, being a true meta-distribution, give users maximum flexibility and control over the system. A stark example of this is the OS upgrade process. Users have a large choice of different command utilities and a bunch of configuration option to choose from to tailor the upgrade process to their needs. This guide will attempt to combine and distill the best practices and recommendations from the Gentoo Wiki/Forums and other sources into a single guide.
TLDR:

emaint sync -a
emerge --ask --verbose --update --newuse --deep @world
dispatch-conf
emerge --ask --depclean
revdep-rebuild
eclean -d distfiles

Preqrequisites

@world
The @world set is a special set that contains all the packages that are installed on the system. It is used to update the system.
I did an overview of sets in Gentoo World Set.

Use flags
Use flags are used to control the compilation of packages. They are used to enable or disable certain features of a package. For example, the X use flag is used to enable or disable the X11 support in a package.
I did an overview of use flags in Gentoo USE Flags.

Command-line tools that might be used during the upgrade Tecnhically emerge can do all the basic steps, but there are other tools that might be useful:

  • eix - search for packages
  • equery - query information about packages
  • emaint - maintenance tool for Portage
  • euse - manage USE flags
  • etc-update - update configuration files (old program)
  • dispatch-conf - update configuration files
  • eselect - manage system configuration
  • elogv - view the latest entries in the Portage logs
  • needrestart - check if a restart is needed after update
  • eclean - clean up obsolete files
  • eclean-kernel - clean up old kernels
  • qcheck - check for broken packages
  • revdep-rebuild - rebuild packages that depend on a package that has been updated
  • glsa-check - check Gentoo Linux Security Advisory for security updates
  • layman - manage overlays

Step 1: Sync Portage Tree

The first step is to sync the Portage tree. This is done by running the following command:

emaint --auto sync

It downloads the latest version of the Portage tree and the metadata from the Gentoo mirrors.

Step 2: Update the System

There are many ways to update the system. To do the most basic full update run:

emerge --ask --verbose --update --newuse --deep @world

Flags:

  • --ask - ask before performing the action
  • --verbose - show more information
  • --update - update to the best available version (not neweset)
  • --newuse - include installed packages where USE flags have changed since compilation
  • --deep - update entire dependency tree, even libraries that are not directly listed in the dependencies of a package

Other options:

  • --keep-going - continue updating even if a package fails to update
  • --oneshot - install package without adding it to the world file

Step 3: Update the Configuration Files

Sometimes after an update configuration files might change. When this happens, Portage create a new config at /etc/portage/config/._cfg0000_etc_file_name_ and leaves the old config at /etc/file_name. dispatch-conf can be used to interactively update the configuration files.

Step 4: Clean up obsolete packages

After multiple updates, some packages might become obsolete (stop being other package’s dependencies). To clean them up run:

emerge --ask --depclean

Step 5: Verify system consistency after cleanup

In some rare case libraries and dependencies might not be installed or be broken. To re-emerge them run:

revdep-rebuild

Step 6: Clean up source code

After multiple updates, some package source files might become obosolete. A common example is Linux kernel source. To clean them up run:

emerge --ask --verbose --depclean

Step 7: Additional (optional) steps

Update Portage itself when needed:

emerge -1v portage

Read the news:

eselect news read

Read update information from logs:

elogv

Check if a restart is needed:

needrestart

Remove old kernels:

eclean-kernel -n 1

References

  • Gentoo Wiki
    • [ Link ] Upgrading the System
  • Gentoo Forums
    • [ Link ] seven steps to upgrade Gentoo System
    • [ Link ] oneshot - need clarification
    • [ Link ] glsa-check
  • Reddit
    • [ Link ] How to upgrade Gentoo without breaking anything?
  • Fitzcarraldo’s Blog
    • [ Link ] My system upgrade procedure for Gentoo Linux
    • [ Link ] Automatically clearing the /usr/tmp/portage directory in Gentoo Linux
  • Stack
    • [ Link ] Optimal procedure to upgrade Gentoo Linux?
  • Github