Differences between revisions 70 and 71
Revision 70 as of 2019-12-04 17:06:16
Size: 6121
Comment: minor fix (clarify)
Revision 71 as of 2020-03-25 20:54:21
Size: 7270
Comment: merged here contents of SearchPackages (almost entirely related to apt-file), added links to package-related pages
Deletions are marked like this. Additions are marked like this.
Line 61: Line 61:

=== apt-file ===

The '''apt-file''' utility, from the package DebianPkg:apt-file can search files contained in Debian packages. It can search in which package a file is included or list the contents of a package without having to install or download it.

 * Searching for a filename: to search for packages that provide a particular filename use `apt-file search <filename>`
 * Listing the contents of a package: to list the contents of a package without the need to install or download it use `apt-file list <packagename>
 * Update the package database: to update the package information database used by apt-file use `apt-file update`

=== Online search using the Debian website ===

It is also possible to use the Debian website Package page both to [[https://www.debian.org/distrib/packages.html#search_packages|search packages]] and to [[https://www.debian.org/distrib/packages.html#search_contents|search in the packages' contents]].
Line 158: Line 170:
 * The main [[Apt]] wiki page  * The main [[Apt]] wiki page
* [[PackageManagement]]
 * [[PackageManagementTools]]
Line 163: Line 177:
{{{#!wiki comment
The above comment seems not relevant anymore since Apt page is now very small and all info were moved elsewhere
}}}

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


This page describes how to use various command line interface package management tools.

Most commands found in the examples must be run as root in a terminal emulator/console. A root console (in GNOME) can most likely be found at Applications > System Tools > Root Terminal. You can also use sudo to edit these files from a console running as normal user account.

Installing, removing and upgrading packages

There are many command-line tools dedicated to package management in Debian. Such programs include aptitude, apt-get or apt. This example uses apt but other packages managers use identical commands.

In the commands below, replace <package> with the name of the package you want to act on.

  • Installing a package: apt install <package>

  • Reinstalling a package: apt reinstall <package>

  • Reinstall a package and all dependencies apt reinstall <package> $(apt-cache depends --recurse --installed <package> ||grep '[ ]')

  • Removing a package: apt remove <package>

  • Removing a package and all its configuration and data files (Caution): apt purge <package>

  • Upgrading a Package: apt upgrade <package>

Keeping your system up-to-date

To upgrade all packages without removing any (safe upgrade):

apt update
apt upgrade

To run package upgrades that require installing or removing some other package, run the following command, and check the packages to be REMOVED: Any package lib<foo> is fine. If it's removing something you use, and there is nothing obviously replacing it (e.g. emacs20 replaced by emacs21), you may want to make yourself a note so you can reinstall it later (when a compatible package is available), or "pin" that package (see the AptPreferences wiki page) before doing the dist-upgrade.

apt dist-upgrade

Search for packages

In addition to the tools mentioned above, you can also use the apt-cache command to search for packages, or apt as described here.

In the commands below, replace <string> with a list of keywords to search for (in package names or descriptions).

apt search <string>

You may want to redirect the output into less (a scrollable viewer) since the list may be huge:  apt search <string> | less 

To search packages only by name you may use dpkg-query -l '*<string>*'

You can also find package information in the following directories:

  • /var/lib/apt/lists/*

  • /var/lib/dpkg/available: list of available packages from repositories.

  • /var/lib/dpkg/status: status of installed and available packages. This file contains information about whether a package is marked for removal or not, whether it is installed or not, etc. A package marked reinst-required is broken and requires re-installation.

apt-file

The apt-file utility, from the package apt-file can search files contained in Debian packages. It can search in which package a file is included or list the contents of a package without having to install or download it.

  • Searching for a filename: to search for packages that provide a particular filename use apt-file search <filename>

  • Listing the contents of a package: to list the contents of a package without the need to install or download it use `apt-file list <packagename>

  • Update the package database: to update the package information database used by apt-file use apt-file update

Online search using the Debian website

It is also possible to use the Debian website Package page both to search packages and to search in the packages' contents.

List installed packages

Use one of the following command to list installed packages:

  •  dpkg --list 

  •  aptitude search ~i 

  •  dpkg-query -l 

  •  dpkg-query -f '${binary:Package}\n' -W 

  •  dpkg -l | grep '^.i' 

  •  apt-cache pkgnames 

  • dpkg --get-selections

To check status of all packages on your system, run dpkg-query -l '*' | less

List files installed by a package

dpkg -L <package>

Restore installed software

On the old system, backup installed packages information:

dpkg --get-selections >/backup/package-selections

Transfer the file backup/package-selections on the new system and run:

apt install $(cat /backup/package-selections | awk '{print $1}')

Simulate operations

Most package managers (apt, aptitude, apt-get..) support the command-line switch --simulate aka -s. This allows one to see what packages would be installed, removed, upgraded, etc by a given operation, without actually doing it. E.g., to see which packages would be installed if you do an upgrade:

apt --simulate upgrade

Delete cached package files

APT maintains a local cache of downloaded/installed .deb packages at /var/lib/apt/cache/. If you want to delete cached package files you've already installed to reclaim some disk space:

apt clean

If you want to retain a local cache of only the most recent versions:

apt autoclean

This will clear the local repository of all the extra packages which can't be downloaded and are largely useless.

Reconfigure packages

When packages are installed, you are sometimes asked to configure them via a wizard (most packages don't require configuration). To show the package configuration again:

dpkg-reconfigure <package>

Find what package a file belongs to

To find out what debian package a particular file belongs to:

dpkg -S /path/to/file

Where /path/to/file is the full path to the file. To find the full path to a binary/program called myprogram, use which myprogram

Find which packages depend on a specific package

To determine which packages depend on a specific package mypackage:

apt-cache rdepends mypackage

To determine which packages build-depend on a specific package mypackage:

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

Further Reading


CategoryPackageManagement | CategorySoftware