Portage

Also known as: emerge

On this page 7

Portage is the source-based package management system of Gentoo Linux, which downloads upstream source code, compiles it locally according to rules in scripts called ebuilds, and installs the result while tracking every file and dependency. Its command-line front end is emerge, the name many administrators use for the whole tool.

In Linux package management, Portage occupies an unusual position: where APT, DNF or Pacman install prebuilt binary packages, Portage treats compilation as the default and lets each system decide which optional features are built into every program. The result is a high degree of control over the installed software, paid for with build time and a steeper learning curve.

How Portage builds and installs software

Portage works by reading ebuilds from a repository tree, resolving the dependency graph, and running each package through a fixed sequence of build phases inside a sandbox. An ebuild is a Bash script with metadata such as the source URL, license, keywords, dependencies and the functions that configure, compile and install the software.

The main repository, historically called the Portage tree and now the Gentoo repository, is synchronized to /var/db/repos/gentoo with emerge --sync. Compiled files are first installed into a temporary image directory, then merged into the live filesystem, and the list of installed files is recorded in the installed package database under /var/db/pkg. That record enables clean removal and collision protection when two packages claim the same file.

The following table lists the main ebuild phases that Portage executes for a typical package.

PhaseWhat happensTypical failure
src_unpackSource archives are extracted into the work directoryCorrupt or missing distfile
src_preparePatches are applied and build files adjustedPatch no longer applies
src_configureBuild system is configured with selected optionsMissing optional library
src_compileSource code is compiled with the configured flagsCompiler error or memory exhaustion
src_installFiles are installed into the image directorySandbox violation
MergeImage is copied to the live system and recordedFile collision with another package
Main ebuild phases in a Portage build

Because every phase runs under the sandbox, a build script that tries to write outside its permitted paths is stopped. This protects the running system from misbehaving build systems, a real concern when thousands of upstream projects are compiled with different tooling.

Key configuration elements of Portage

Portage is configured mainly through make.conf and the package.* files under /etc/portage, which together decide what is built, how it is optimized and which versions are allowed. The central mechanism is the USE flag, a keyword that switches an optional feature on or off at build time, for example ssl, wayland or doc.

Global defaults come from a profile, selected with eselect profile, which sets baseline USE flags and package masks for a desktop, server or hardened system. Local settings then override the profile. The next table summarizes the settings that most affect daily use.

SettingLocationWhat it controls
USEmake.conf or package.useOptional features compiled into packages
CFLAGS and CXXFLAGSmake.confCompiler optimization, such as -O2 -march=native
MAKEOPTSmake.confParallel build jobs, often about one per CPU thread
ACCEPT_KEYWORDSmake.conf or package.accept_keywordsStable versus testing branch per architecture
FEATURESmake.confBehaviors such as buildpkg, sandbox or parallel-fetch
package.mask/etc/portageVersions that must never be installed
Important Portage settings and their effect

Packages also carry slots, which allow several major versions of the same software to be installed side by side, and subslots, which tell Portage when dependent packages must be rebuilt after a library changes its ABI. This slot-operator dependency mechanism is one of the most precise rebuild-tracking systems among Linux package managers.

Portage compared with binary package managers

Portage differs from binary package managers mainly in where the build happens and who decides the build options. APT with dpkg, DNF with RPM, and Pacman install packages compiled once by the distribution, so every user receives the same feature set. Portage moves that decision to the local system.

The comparison below shows how Portage relates to several neighbors in the same field.

ToolDefault package formBuild customizationTypical distribution
PortageSource ebuilds, optional binariesPer-package USE flags and compiler flagsGentoo, ChromeOS SDK
APTPrebuilt .deb packagesLimited, through rebuilding sourcesDebian, Ubuntu
DNFPrebuilt RPM packagesLimited, through rebuilding spec filesFedora, RHEL
PacmanPrebuilt packagesThrough PKGBUILD and the AURArch Linux
NixDerivations with binary cacheFull, expressed in the Nix languageNixOS
Portage and related package managers

The closest conceptual relatives are the BSD ports systems, which inspired Portage, and Nix or GNU Guix, which also describe builds from source but add reproducible, isolated store paths. Portage installs into the conventional filesystem hierarchy, so it does not offer atomic rollbacks in the way Nix does.

Working with emerge in practice

Day-to-day administration with Portage revolves around a small set of emerge commands for synchronizing, updating, inspecting and cleaning the system. The --ask and --pretend options show the planned actions, including changed USE flags, before anything is compiled, which is the safest habit for any update.

The decision table below maps common administrative tasks to the usual commands.

TaskCommandReason
Refresh the repositoryemerge –syncFetches current ebuilds and metadata
Update the whole systememerge -avuDN @worldUpgrades and rebuilds for changed USE flags
Install a packageemerge -av app-editors/vimShows the plan and asks for confirmation
Remove orphaned dependenciesemerge –depclean -aRemoves packages nothing requires
Rebuild after library changesemerge @preserved-rebuildRepairs consumers of replaced libraries
Search for a packageemerge –search or eixFinds category and package names
Common emerge tasks

Since 2023, Gentoo has published an official binary package host for common architectures, and Portage can use it through the getbinpkg feature. Administrators can also build packages once on a fast machine with buildpkg and distribute them to slower hosts, combining source flexibility with binary installation speed.

Limitations and common mistakes with Portage

The main costs of Portage are long build times and complex dependency conflicts, both of which grow with poorly maintained configurations. Compiling a large web browser or office suite can take several hours on modest hardware, and toolchain updates may trigger rebuilds of many packages.

  • Aggressive compiler flags such as -O3 or unsafe math options rarely bring measurable gains and can produce subtle bugs.
  • Infrequent updates let the system drift far from the repository, which makes blocker and slot conflicts much harder to resolve.
  • Ignoring news items from eselect news leads administrators to miss required manual migration steps.
  • Mixing stable and testing keywords globally pulls in large parts of the testing branch instead of a single package.
  • Skipping configuration updates reported by dispatch-conf or etc-update leaves outdated files in place.

A widespread misconception is that source compilation makes Gentoo automatically faster than binary distributions. In practice, the measurable benefits come from removing unneeded features and dependencies, not from generic optimization flags, and the performance difference on modern hardware is usually small.

Stripped to the essentials

Most Linux systems install programs that were already assembled somewhere else, like buying furniture fully built. Portage works more like receiving the parts and a detailed instruction sheet, then assembling each piece at home exactly the way you want it.

You decide which extras go in and which stay out, so the finished system contains only what you asked for. The price is time: assembly happens on your own computer, and large programs can take hours. The key idea is simple: Portage trades installation speed for control over every program on the machine.

Where it is applied

A small hosting provider runs a fleet of twenty identical Gentoo servers that serve web applications. The administrator wants a lean system without graphical libraries, so the profile is set to a server profile and the global USE line disables X, gtk and wayland while enabling ssl and threads.

Instead of compiling on every server, one build host with 16 CPU threads runs emerge -avuDN @world weekly with FEATURES=”buildpkg” and MAKEOPTS="-j16". The resulting binary packages are shared over the internal network, and the production servers install them with the --usepkg option in a few minutes.

The outcome is a consistent, minimal fleet with a smaller attack surface, updates that finish quickly on production machines, and a single place where USE flags and compiler settings are reviewed before anything reaches customers.