Translation(s): English - Français - Italiano - 한국어(Korean) - Nederlands - Romana


How to use aptitude, apt and apt-get. For more information about package managers, see DebianPackageManagement. For general packaging information, see PackageManagement.

/!\ This page assumes you have read HowToInstallPackages

Contents

  1. Basic usage
    1. Choosing a package manager
    2. Updating your package list
    3. Keeping your system up-to-date
    4. Finding packages to install, remove or upgrade
    5. Installing, removing and upgrading packages
  2. Advanced usage
    1. Install a package file outside of a repository
    2. Reconfigure packages
    3. Delete cached package files
    4. List installed packages
    5. Find relationships between different packages
    6. Find relationships between files and packages
  3. See also

Basic usage

Choosing a package manager

Debian offers several package managers. They all use the same underlying technology, so it's fine to try them out and see which one you like best.

aptitude

Includes a text user interface via ncurses - good if you need to use a terminal but want a menu system

apt
Modern command-line intefrace - good if you want to install a package manually
apt-get
Debian's original package manager - good if you want to write a script that does some package management
  • the term "apt-get" refers both to the specific program apt-get, and to the suite it's part of, including e.g. apt-cache

{i} Online examples often recommend apt-get - it's the most widely available, so authors get fewer confused replies that way. Use whichever package manager they recommend while following the example, then go back to using your favourite when you're done.

Updating your package list

Debian packages are stored in repositories (usually websites, but can also be local files). Websites can't automatically push updates to your computer, so you need to tell your package manager to pull them:

# Choose your favourite - they all do the same thing:
sudo aptitude update
sudo apt update
sudo apt-get update

{i} Update your package list whenever you start installing or updating packages.

Keeping your system up-to-date

New versions of packages are released from time to time. In Debian Stable, they usually just fix the occasional bug or security issue. In the testing and unstable versions of Debian, updates frequently add new features.

You should upgrade all your packages regularly. For details, see Upgrading your system.

# Safe upgrade - choose your favourite:
sudo aptitude update && sudo aptitude safe-upgrade
sudo apt update && sudo apt upgrade
sudo apt-get update && sudo apt-get upgrade

# Full upgrade - choose your favourite:
sudo aptitude update && sudo aptitude full-upgrade
sudo apt update && sudo apt full-upgrade
sudo apt-get update && sudo apt-get full-upgrade

# Remove unwanted packages after a safe upgrade:
# (not supported in aptitude)
sudo apt autoremove
sudo apt-get autoremove

Finding packages to install, remove or upgrade

Each package manager takes a different approach to search. See also Finding packages to install, which discusses advanced techniques for finding packages.

aptitude

Do sudo aptitude to start the program interactively. Either look through the package tree, or press / to search by package name.

apt

Do apt search <string> to search for packages that include the specified string

  • apt searches the package's full description, but only shows the first line - you may need to do apt show <package>

apt-get

Do apt-cache search <string> to search for packages that include the specified string

  • apt-get itself just gets packages, this command uses apt-cache to search the cache

  • whereas apt search is designed to look good to a human eye, apt-cache search is designed for use with tools like grep or less

{i} Each of these tools has strengths and weaknesses - you might like to search for packages with one program but install them with another.

Installing, removing and upgrading packages

Package managers all install packages the same way. Replace <package> below with the name of your package:

# Install a package, or upgrade an existing one - choose your favourite:
sudo aptitude update && sudo aptitude install <package>
sudo apt update && sudo apt install <package>
sudo apt-get update && sudo apt-get install <package>

# Uninstall an existing package - choose your favourite:
sudo aptitude remove <package>
sudo apt remove <package>
sudo apt-get remove <package>

The install command won't touch a package that already exists and is up-to-date. If you need to remove and reinstall a package (e.g. because you accidentally deleted some files), use the reinstall command to remove and reinstall it without affecting its dependencies.

The remove command won't touch edited configuration files. If you need to remove absolutely everything (e.g. because you installed the package by accident), use the purge command instead. Note that you can purge a package even after you remove it, and you can use autopurge instead of autoremove.

The commands ask for confirmation if they need to modify other packages (e.g. installing a dependency). Use install -yy to act as if you said yes to every question, or use install --simulate to see what would be done without actually installing anything.

{i} apt and apt-get resolve dependencies in a fairly simplistic way. If you find they keep trying to (un)install the wrong packages, you might prefer aptitude's interactive score-based resolver.

Advanced usage

Install a package file outside of a repository

If you downloaded a .deb file manually:

#aptitude does not support installing .deb files manually
sudo apt install /path/to/package.deb
sudo apt-get install /path/to/package.deb

Reconfigure packages

Some packages ask questions during installation. To change your answers:

dpkg-reconfigure <package>

For details, see debconf.

Delete cached package files

Packages are downloaded to /var/cache/apt/archives during installation, and left there in case you need to reinstall them after the package is removed from the repository. To remove those files:

# Clear old versions you're unlikely to need again:
sudo apt autoclean
# Clear all cached files:
sudo apt clean

List installed packages

Sometimes you need a list of packages that have been installed, or have been removed but not purged. There are several tools to do this, based on your needs:

# Packages with their status:
dpkg --get-selections

# Detailed information about packages:
dpkg-query --list

# Detailed information, with custom formatting:
dpkg-query --show -f '${binary:Package}\n'

The output of these commands are designed to be used with other commands, like grep or sed. For example:

# show the names of installed packages:
dpkg-query -f '${db:Status-Status} ${binary:Package}\n' -W \
 | sed -n -e 's/^installed //p'

# show the names of packages that have been removed but not purged:
dpkg-query -f '${db:Status-Status} ${binary:Package}\n' -W \
 | sed -e '/^installed /d' -e 's/^[^ ]* //'

{i} One common use for these commands is to install packages on a new system - make a list of installed files with a command above, then do sudo apt install $(cat installed-packages.txt) on the new system.

Find relationships between different packages

The dependencies of each package are stored in a database, which you can query:

# Show information about a package, including the other packages it depends on:
apt show <package>

# List packages that depend on a package:
apt rdepends <package>

# Also list packages that depend on those packages, and so on:
apt rdepends --recurse <package>

If you've added deb-src lines to your /etc/apt/sources.list files, you can also query for build-dependencies:

grep-dctrl -F Build-Depends <package> -s Package /var/lib/apt/lists/*Sources
grep-dctrl -F Build-Depends-Indep <package> -s Package /var/lib/apt/lists/*Sources

Find relationships between files and packages

When a package is installed, the files associated with it are stored in a database, which you can query:

# List all files in a package:
dpkg -L <package>
# Show the package a file is in:
dpkg -S /path/to/file
# Show the package a program is in:
dpkg -S "$(which <program>)"

{i} dpkg -S is quite slow and only works for installed packages - see apt-file for an alternative.

See also


CategoryPackageManagement | CategorySoftware

AltStyle によって変換されたページ (->オリジナル) /