The main Portage tool that most users will use is emerge. We have already
used it during the Gentoo installation and in the previous chapter, but we just
briefly explained how to use it. This chapter will elaborate on emerge
and learn you how to use emerge to fix all your software-related needs.

emerge is the command used to install, remove, query and maintain
software packages. It is a front-end for ebuild; people interested in
becoming Gentoo professionals will learn how to use ebuild later on. For
now, we will focus on emerge as it has functionality that ebuild
lacks (such as resolving dependencies, searching the Portage tree, etc.).

Since emerge is the most important tool for Gentoo users, it has an
extensive manpage you can read by issuing man emerge. You can also view
the in-command help by running emerge --help.

# man emerge
# emerge --help

The Portage Tree

Before we continue describing emerge, let us first take a look at the
Portage Tree. Go to /usr/portage and do a listing of the available
directories. We use ls --classify to list the contents of a
directory as it will show directories with a trailing "/".

Remember that we told you that a Gentoo package is called an ebuild? Well, in
the example directory four of such ebuilds are stored. Their naming is
almost identical: they only differ in the version name.
You are free to view the contents of such a package: they are plain scripts. We
will not discuss it right now as it isn't important to know if you plan on just
using Gentoo.

The other files are the ChangeLog (which contains a listing of all
the changes done to the ebuilds), Manifest (which contains the
checksums and permissions of all the files in the directory) and
metadata.xml (which contains more information about the package,
such as the responsible development group -- called herd -- and a more
extensive description).

Inside the files directory you will find extra files, needed by
Portage: digests (checksums and permissions of the files needed by a single
version of the package), patches, example configuration files, etc.

If you go back to the root of the Portage tree (/usr/portage) you
will notice that there are other, non-category directories too. We will discuss
those later in this chapter.

Search for a Package

If you are new to Linux or Gentoo, you might not know what tool you need for
what job. To facilitate searching, emerge provides you with a way to
search through the available packages on your system. There are two ways you can
search through packages: by name, or by name and
description.

To search through the Portage tree by name, use emerge search. For
instance, to find out more about mozilla:

As you can see, the output of emerge informs you about the category and
name of the package, the available version, the currently installed version,
the size of the downloaded files, the homepage and the small description.

You see something new? Yes, downloaded files. When you tell Portage to
install a package, it of course needs to have the necessary sources (or
precompiled packages) available. It therefore checks the contents of
/usr/portage/distfiles (for sourcecode) or
/usr/portage/packages/All (for precompiled packages) to see if the
necessary files are already available. If not, it downloads the necessary files
and places them in those directories.

Searching the Portage Tree, especially when using --searchdesc, is very
time consuming. There are other, more performant tools available. We will
describe those in the chapter on Gentoolkit and
Other Tools.
Viewing the ChangeLog

While browsing through the Portage Tree, you saw that there was a ChangeLog for
each package. You can view this ChangeLog with emerge too. Use the
--pretend --changelog (-pl in short) options. As an example we
will view the ChangeLog entries for gnumeric:

# emerge --pretend --changelog gnumeric

Updating PortageIntroduction

Searching through Portage is nice, but if you don't update your Portage Tree
regularly, you will be stuck with the packages and versions available on your
system. This means that your system will get outdated pretty soon and that
you will be missing bugfixes and remedies for possible security problems.

There are several ways to update your Portage Tree. The most popular method is
by using one of our rsync mirrors.
Another one is by using a Portage snapshot (in case a firewall or unavailability
of a network prohibits the use of the rsync server).

Selecting a Mirror for rsync

It is adviseable to first select a fast mirror close to you. You can do this manually
(by setting the SYNC variable in /etc/make.conf) or use
mirrorselect to do this for you automatically. As the SYNC
variable will be discussed later on, we will focus on using mirrorselect.
First install mirrorselect by emerging it:

# emerge --usepkg mirrorselect

Now run mirrorselect to automatically select mirrors for you (it will
also setup Portage to use a mirror for the sourcecode):

# mirrorselect -a -s3

Updating Portage

To update Portage using rsync, simply run emerge sync:

# emerge sync

If this fails (due to network problems, or a firewall), you can try using
emerge-webrsync which will download a Portage Tree snapshot using
wget. This also means that you can use proxies if you want. We discussed
how to setup your system to use proxies during the Gentoo installation.

# emerge-webrsync

Maintaining SoftwareBuilding or Prebuild?

Gentoo provides ebuilds, the Gentoo packages if you like. But when you want to
install such an ebuild, you can choose between building the package, or
using a prebuild package. But what are the advantages/disadvantages of
both approaches, and can they be used next to each other?

As you probably have guessed, building packages takes a lot of time (especially
if you have little resources or want to build big packages, such as KDE, OpenOffice.org, etc.). By building the
package, you can use the USE setting to tweak the package to your system.
Of course, you can also define high optimization options (in the CFLAGS
and CXXFLAGS variables) to compile the package with.

Using prebuild packages improves the installation time (as no more compilation
is needed), but you will lose the advantages of the USE setting and the
CFLAGS & CXXFLAGS variables.

As previously stated, prebuild packages are stored in the
/usr/portage/packages/All directory, while the sourcecode of the
packages are placed in /usr/portage/distfiles. If you have finished
installing a package you can remove the package or sourcecode from the
respective directory. However, you might want to keep the package/sourcecode of
the latest version, just in case you want to reinstall the package (so you don't
have to redownload it).

Installing Software from Sources

Okay, enough talking, let's cut to the chase. To install a package, you will use
the emerge command. If you don't want to use any prebuild packages, you
can just use emerge <package-name> or emerge
<category>/<package-name>. As an example we'll install
gnumeric:

# emerge gnumeric

This will download the sourcecode for you and unpacks, compiles and installs the
package on your system. It will also do the same for all the dependencies. If
you want to see what dependencies will be installed with it, use the
--pretend option (-p in short):

# emerge --pretend gnumeric

If you want to download the sourcecode of the package and its dependencies,
but don't want to build the package, use the --fetchonly option
(-f in short):

# emerge --fetchonly gnumeric

If you want to see where emerge downloads the sources from, combine the
--fetchonly and --pretend options:

# emerge --fetchonly --pretend gnumeric

You can also opt to install a specific version of a package.
For instance, if you want to install a gnumeric version older than 1.2 -- for
any reason whatsoever :) you would type:

# emerge "<gnumeric-1.2"

Other possibilities are of course ">" (later version) and "=" (the exact
version).

Installing Prebuild Packages

When you want to install a prebuild package, you should use the --usepkg
option (-k in short). This will use the binary package available in
/usr/portage/packages/Allif the package and the version of
the application you want to install match.

# emerge --usepkg gnumeric

If you want to use the binary package, even if the versions don't match, use
--usepkgonly (-K in short).

# emerge --usepkgonly gnumeric

If you don't have the prebuild package on your system yet, you can have
emerge download it from a mirror, defined in the PORTAGE_BINHOST
variable declared in /etc/make.conf.

To download the binary package in case this package doesn't exist on
your system already, use --getbinpkg (-g in short):

# emerge --getbinpkg gnumeric

This will download the package and the package-related information for you and
install it on your system, together with the dependencies. If you want to see
what dependencies will be installed with it, use the --pretend option
(-p in short):

# emerge --ginbinpkg --pretend gnumeric

You can also opt to download the prebuild package (and the package-related
information) without checking the information on your local system and
without using the prebuild package already on your system (if
applicable), use the --getbinpkgonly option (-G in short):

# emerge --getbinpkgonly gnumeric

You can also opt to install a specific version of a package.
For instance, if you want to install a gnumeric version older than 1.2 -- for
any reason whatsoever :) you would type:

# emerge --usepkg "<gnumeric-1.2"

Other possibilities are of course ">" (later version) and "=" (the exact
version).

Updating your System

Portage knows two special tags to denote a set of software packages:
system and world. You have already seen the former while
installing Gentoo if you didn't use a stage3 installation. To refresh
things: system is the collection of core packages, necessary to
have a working Gentoo system.

The world tag consists of all software you have installed yourself on
your system plus the system information. In other words, every time you
emerge a package using emerge <package-name>, the
<package-name> is registered in the world file
(/var/cache/edb/world). Dependencies are not part of the
world file, but we will get to that later.

If you want to update the system packages, use the --update option
(-u in short):

# emerge --update system

An identical approach can be used for the world packages:

# emerge --update world

Again, if you want to see what emerge wants to update, use the
--pretend option together with the --update option:

Right next to the word "ebuild" you will notice a letter (or combination of
letters) which gives you more information about the package:

B (blocks) The package listed to the left is blocking the emerge of
the package listed to the right

N (new) The package is new to your system and will be emerged for the
first time

R (reemerge) The package isn't new, but needs to be reemerged

F (fetch) The package requires that you download the sourcecode
manually (for instance due to licencing issues)

U (update) The package already exists on your system but will be
upgraded

UD (downgrade) The package already exists on your system but will be
downgraded

U- (slot warning) The package you have installed on your system
is listed as a package that can not coexist with a different version, but
your update does. The update will be installed and the older version will be
removed.

In certain cases, an update may mean a downgrade (i.e. install an older version
instead of a newer version). If you don't want this to happen, use the
--upgradeonly option (-U in short):

# emerge --update --upgradeonly world

Of course, we are talking here about system and world, but you can
perform the same actions for individual software packages.

Removing Software

If you want to remove software from your system, you can use the unmerge
option (-C - capital C - in short):

# emerge unmerge gnumeric

If you want to test a removal (but not perform it), you can use --pretend
again:

# emerge --pretend unmerge gnumeric

Portage doesn't verify if a package is a dependency for another
installed package. It also doesn't warn you if the package is part of
system, i.e. a core application necessary for the correct functioning of
your system!
Software AvailabilityARCH or not?

Gentoo places its packages in two possible stadia called ARCH and
~ARCH. Don't take this literally: the stadia depend on the architecture
you are using. In other words, for x86-based systems you have x86 and
~x86, for ppc-based systems you have ppc and ~ppc etc.

The ~ARCH stadium means that the package works for the developer in
charge of the package, but that the package hasn't been tested thoroughly enough
by the community to be placed in ARCH. ~ARCH packages usually go
to ARCH after being bugfree for a sufficient amount of time.

Your system will use ARCH packages per default. If you want to live on
the edge, don't mind having a broken package once in a while, and you like
submitting bugreports to bugs.gentoo.org, then you can opt to use
~ARCH packages. To "move" your system to a ~ARCH-using system,
edit the ACCEPT_KEYWORDS variable in /etc/make.conf so that
it reads ~ARCH (again: for x86-based systems: ~x86, etc.).

If you want to update your system now, you will notice that a lot of
packages will be updated!

Masked Packages

When you want to install a package, you might come across the following message:

Calculating dependencies
!!! all ebuilds that could satisfy <your package> have been masked.

A package can be masked due to two reasons:

The package is in ~ARCH while you use ARCH

The package is hard-masked explicitly

If the package is masked because of the first reason, and you really want
to install it (knowing that there is a reason why it isn't available in
ARCH), you can temporarily accept ~ARCH packages:

# ACCEPT_KEYWORDS="~x86" emerge gnumeric

A package is hardmasked if it is listed in
/usr/portage/profiles/package.mask. If you read this file, you
will also read the reason why the package is hardmasked (it is usually added as
a comment). If you want to install the package nevertheless (despite all the
possible warnings we could ever throw at your head about "breaking your system",
"breaks other packages", or "badly needs testing"), create the
/etc/portage/package.unmask file and list the package in it (use
the same format as is used in /usr/portage/profiles/package.mask).

Do not alter the /usr/portage/profiles/package.mask file as
all changes are undone the next time you update your Portage tree.

Another trick to circumvent the "masked package" problem is to install the
package using the full path. This will ignore both the ACCEPT_KEYWORD
settings and the package.mask listing.

# emerge /usr/portage/app-office/gnumeric/gnumeric-1.2.0.ebuild

Blocked Packages

You have a situation when you receive the following error on your screen: