A practical guide to Fedora and Red Hat Enterprise Linux, 7th Edition (2014)

Part VI: Appendixes

D. Keeping the System Up-to-Date Using apt-get

In This Appendix

Using apt-get to Install, Remove, and Update Packages

Using apt-get to Upgrade the System

Other apt-get Commands

Repositories

sources.list: Specifies Repositories for apt-get to Search


The apt-get utility fills the same role as yum, described in Chapter 12: They install and update software packages. Both utilities compare the files in a repository (generally on the Internet) with those on the local system and update the files on the local system according to your instructions. Both utilities automatically install and update any additional files that a package depends on (dependencies). Most Linux distributions come with apt-get or yum. Debian-based systems such as Ubuntu and Mint are set up to use apt-get, which works with deb packages. RHEL (Red Hat Enerprise Linux) and Fedora use yum, which works with rpm packages. There are also versions of apt-get that work with rpm packages.

To facilitate the update process, apt-get and yum keep locally a list of packages that are held in each of the repositories they use. Any software you want to install or update must reside in a repository.

When you give apt-get or yum a command to install a package, they look for the package in a local package list. If the package appears in the list, apt-get or yum fetches both that package and any packages the package you are installing depends on and installs the packages.

The apt-get examples in this section are from an Ubuntu system. Although the files, input, and output on the local system might look different, how you use the tools—and the results—will be the same.

Image apt-get and dpkg

APT (Advanced Package Tool) is a collection of utilities that download, install, remove, upgrade, and report on software packages. APT utilities download packages and call dpkg utilities to manipulate the packages once they are on the local system. For more information refer tohelp.ubuntu.com/community/AptGet/Howto.

Updating the package list

The primary APT command is apt-get; its arguments determine what the command does. Working with root privileges, give the command apt-get update to update the local package list:

apt-get update
Get:1 http://extras.ubuntu.com precise Release.gpg [72 B]
Get:2 http://security.ubuntu.com precise-security Release.gpg [198 B]
Hit http://extras.ubuntu.com precise Release
Get:3 http://security.ubuntu.com precise-security Release [49.6 kB]
Hit http://extras.ubuntu.com precise/main Sources
Get:4 http://us.archive.ubuntu.com precise Release.gpg [198 B]
Hit http://extras.ubuntu.com precise/main i386 Packages
Get:5 http://us.archive.ubuntu.com precise-updates Release.gpg [198 B]
Get:6 http://us.archive.ubuntu.com precise-backports Release.gpg [198 B]
Get:7 http://us.archive.ubuntu.com precise Release [49.6 kB]
Get:8 http://security.ubuntu.com precise-security/main Sources [22.5 kB]
Get:9 http://security.ubuntu.com precise-security/restricted Sources [14 B]
...
Fetched 13.4 MB in 2min 20s (95.4 kB/s)
Reading package lists... Done

Check the dependency tree

The apt-get utility does not tolerate a broken dependency tree. To check the status of the local dependency tree, give the command apt-get check:

apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done

The easiest way to fix errors that apt-get reveals is to remove the offending packages and then reinstall them using apt-get.

Image Using apt-get to Install, Remove, and Update Packages

Installing packages

The following command uses apt-get to install the zsh package:

apt-get install zsh
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  zsh-doc
The following NEW packages will be installed:
  zsh
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/4,667 kB of archives.
After this operation, 11.5 MB of additional disk space will be used.
Selecting previously unselected package zsh.
(Reading database ... 166307 files and directories currently installed.)
Unpacking zsh (from .../zsh_4.3.17-1ubuntu1_i386.deb) ...
Processing triggers for man-db ...
Setting up zsh (4.3.17-1ubuntu1) ...
update-alternatives: using /bin/zsh4 to provide /bin/zsh (zsh) in auto mode.
update-alternatives: using /bin/zsh4 to provide /bin/rzsh (rzsh) in auto mode.
update-alternatives: using /bin/zsh4 to provide /bin/ksh (ksh) in auto mode.

Removing packages

Remove a package the same way you install a package, substituting remove for install:

apt-get remove zsh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  zsh
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 11.5 MB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 167467 files and directories currently installed.)
Removing zsh ...
Processing triggers for man-db ...

To ensure you can later reinstall a package with the same configuration, the apt-get remove command does not remove configuration files from the /etc directory hierarchy. Although it is not recommended, you can use the purge command instead of remove to remove all the package files, including configuration files. Alternately, you can move these files to an archive so you can restore them later if necessary.

Image Using apt-get to Upgrade the System

Two arguments cause apt-get to upgrade all packages on the system: upgrade upgrades all packages on the system that do not require new packages to be installed and dist-upgrade upgrades all packages on the system, installing new packages as needed; this argument will install a new version of the operating system if one is available.

The following command updates all packages on the system that depend only on installed packages:

apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
  eog libtiff4
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 906 kB of archives.
After this operation, 20.5 kB disk space will be freed.
Do you want to continue [Y/n]? y
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libtiff4 i386 3.9.5-2ubuntu1.1 [142 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main eog i386 3.4.2-0ubuntu1 [763 kB]
Fetched 906 kB in 2s (378 kB/s)
(Reading database ... 167468 files and directories currently installed.)
Preparing to replace libtiff4 3.9.5-2ubuntu1 (using .../libtiff4_3.9.5-2ubuntu1.1_i386.deb) ...
Unpacking replacement libtiff4 ...
Preparing to replace eog 3.4.1-0ubuntu1 (using .../eog_3.4.2-0ubuntu1_i386.deb) ...
Unpacking replacement eog ...
Processing triggers for libglib2.0-0 ...
Processing triggers for man-db ...
Processing triggers for gconf2 ...
Processing triggers for hicolor-icon-theme ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf.index...
Processing triggers for desktop-file-utils ...
Processing triggers for gnome-menus ...
Setting up libtiff4 (3.9.5-2ubuntu1.1) ...
Setting up eog (3.4.2-0ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

When apt-get asks whether you want to continue, enter Y to upgrade the listed packages; otherwise, enter N. Packages that are not upgraded because they depend on packages that are not already installed are listed as kept back.

Use dist-upgrade to upgrade all packages, including packages that depend on packages that are not installed. This command also installs dependencies.

Image Other apt-get Commands

autoclean

Removes old archive files.

check

Checks for broken dependencies.

clean

Removes archive files.

dist-upgrade

Upgrades packages on the system, installing new packages as needed. If a new version of the operating system is available, this option upgrades to the new version.

purge

Removes a package and all its configuration files.

source

Downloads source files.

update

Retrieves new lists of packages.

upgrade

Upgrades all packages on the system that do not require new packages to be installed.

Repositories

Repositories hold collections of software packages and related information, including headers that describe each package and provide information on other packages the package depends on. Typically, a Linux distribution maintains repositories for each of its releases.

Software package categories

Software packages are frequently divided into several categories. Ubuntu uses the following categories:

• main—Ubuntu-supported open-source software

• universe—Community-maintained open-source software

• multiverse—Software restricted by copyright or legal issues

• restricted—Proprietary device drivers

• backports—Packages from later releases of Ubuntu that are not available for an earlier release

The apt-get utility selects packages from repositories it searches based on the categories specified in the sources.list file.

Image sources.list: Specifies Repositories for apt-get to Search

The /etc/apt/sources.list file specifies the repositories apt-get searches when you ask it to find or install a package. You must modify the sources.list file to enable apt-get to download software from nondefault repositories. Typically, you do not need to configure apt-get to install supported software.

Each line in sources.list describes one repository and has the following syntax:

type URI repository category-list

where type is deb for packages of executable files and deb-src for packages of source files; URI is the location of the repository, usually cdrom or an Internet address that starts with http://repository is the name of the repository apt-get is to search; and category-list is a SPACE-separated list of categories apt-get selects packages from. Comments begin with a pound sign (#) anywhere on a line and end at the end of the line.

The following line from sources.list on an Ubuntu system causes apt-get to search the Precise archive located at us.archive.ubuntu.com/ubuntu for deb packages that contain executable files. It accepts packages that are categorized as mainrestricted, and multiverse:

deb http://us.archive.ubuntu.com/ubuntu/ precise main restricted multiverse

Replace deb with deb-src to search for packages of source files in the same manner. Use the apt-get source command to download source packages.

Default repositories

The default sources.list file on an Ubuntu system includes repositories such as precise (Precise as originally released), precise-updates (major bug fixes after the release of Precise), precise-security (critical security-related updates), and precise-backports (newer, less-tested software that is not reviewed by the Ubuntu security team). Some repositories in sources.list might be commented out. Remove the leading pound sign (#) on the lines of the repositories you want to enable. After you modify sources.list, give the command apt-get update (page 1184) to update the local package indexes.

The next line, which was added to sources.list, enables apt-get to search a third-party repository (but see the following security tip):

deb http://download.skype.com/linux/repos/debian/ stable non-free

In this case, the repository is named stable and the category is non-free. Although the code is compiled for Debian, it runs on Ubuntu, as is frequently the case.


Security: Use repositories you trust

There are many repositories of software packages. Be selective regarding which repositories you add to sources.list: When you add a repository, you are trusting the person who runs the repository not to put malicious software in packages you might download. In addition, unsupported packages might conflict with other packages or cause upgrades to fail.