Differences between revisions 41 and 71 (spanning 30 versions)
Revision 41 as of 2011-04-05 20:18:37
Size: 6230
Editor: FranklinPiat
Comment: fix link
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 2: Line 2:
||<tablestyle="width: 100%;" style="border: 0px hidden">~-Translation(s): [[fr/AptCLI|Français]] - [[it/AptCLI|Italiano]] - [[AptCLIDutch|Nederlands]]-~||<style="text-align: right;border: 0px hidden"> (!) [[/Discussion|Discussion]]|| ~-[[DebianWiki/EditorGuide#traduction|Translation(s)]]: English - [[fr/AptCLI|Français]] - [[it/AptCLI|Italiano]] - [[nl/AptCLI|Nederlands]] - [[ko/AptCLI|한국어(Korean)]]-~
Line 4: Line 4:
This page describes how to use various CLI (command line interface) Apt tools.
This page describes how to use various [[CommandLineInterface|command line interface]] [[PackageManagementTools|package management tools]].
Line 8: Line 9:
(Note: A CLI or [[Root|root]] console (in GNOME) can most likely be found at "Applications -> System Tools-> Root Terminal", and "Applications -> System Tools-> Terminal" for a normal user console.)

{{http://www.vanadac.com/~dajhorn/projects/lmsw/10%20Spam/01%20apt-get%20install%20perlstuff.png}} [[[AptGetInstallPerlStuffDescription|D]]]

== Configuring Apt Sources ==

Apt downloads packages and installs them onto your computer. To do that it connects to software repositories, or sources, which contain all the packages you'd want. You can configure Apt to use a source (or multiple sources) to get these packages from. There are many sources - web (HTTP) servers, FTP servers, CD-ROM disks, network servers (etc). Generally users download packages from the internet, since most users don't download all 14 CD's (for the current Sarge release).

=== Editing Sources Directly ===

You can edit the file which determines your sources directly:

Open a [[Root|root]] console
{{{
# nano /etc/apt/sources.list
}}}
or
{{{
# gedit /etc/apt/sources.list
}}}
Edit!

You should read the manual for this configuration file first - type "{{{man sources.list}}}" at a console window. You could also read the [[SourcesList|sources.list]] page.

=== Using apt-setup ===

You can use the '''apt-setup''' tool which generates automatic source lines and adds them to the /etc/apt/sources.list (the file which configures your apt sources). Note: apt-setup doesn't wipe your existing configuration - it simply appends more sources. apt-setup is a [[DebConf|debconf]] wizard.

Note: apt-setup was part of base-config which is no longer available in DebianEtch or DebianUnstable, please refer to [[DebianInstaller/RemoveBaseConfig]] and to http://lists.debian.org/debian-boot/2005/12/msg00259.html for details.

Open a root console
{{{
# apt-setup
}}}
Follow the Wizard!

=== Using apt-spy ===

apt-spy will generate a sources.list file (the configuration file for apt package sources) for you! It measures the latency and bandwidth to servers, and picks the best one.

To get started, you'll need to install it, and then read how to use it:

Open a root console
{{{
aptitude install apt-spy
{{{#!wiki tip
Most commands found in the examples must be run as [[Root|root]] in a [[TerminalEmulator|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.
Line 55: Line 13:
When using apt-spy you need to at least include {{{-d}}} and the Debian distribution you want to check.
Example first time usage:
== Installing, removing and upgrading packages ==

There are many command-line tools dedicated to package management in Debian. Such programs include [[aptitude|aptitude]], [[apt-get|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):
Line 58: Line 31:
# apt-spy -d stable apt update
apt upgrade
Line 61: Line 35:
This command will check all the Debian stable repositories to see which ones are the fastest. If you want to only check the repositories where you live at you would include {{{-a}}} and the location which includes North America, South America, Asia, Europe, and Australia and New Zealand. 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}}}.
Line 63: Line 37:
==== Apt-spy options ====


 *-d distribution - Debian distribution (ie, stable). Required unless updating.
 *-a area - Area to benchmark. (eg, Europe).
 *-c config - Configuration file to use.
 *-e number - Number of servers to benchmark before exiting.
 *-f file - File to grab when benchmarking. (relative to Debian base).
 *-i file - Specify input file. For use with the -w option.
 *-m mirror-list - Mirror list to use, or mirror-list to update when updating.
 *-o output-file - Where to put output.
 *-p proxy - Proxy server to use.

=== Using a graphical program ===

If you are using Gnome ''(I don't know for KDE)'' which is the default in Debian, you can configure your Apt sources with a graphical program. You will found it in:
 * for Etch: Desktop ''menu'' -> Administration -> Software Properties

You'll be prompted for [[Root#Password|Root password]]

== Installing Packages ==

Open a root console
Line 87: Line 38:
# aptitude install <package>
}}}
 where <package> is the name of the package (application) you want to install.

== Reinstalling ==

To reinstall a package type in a terminal:
{{{
aptitude reinstall <package>
}}}
To reinstall with all dependencies, type:
{{{
# aptitude reinstall <package> $(apt-cache depends --recurse --installed <package> ||grep '[ ]')
apt dist-upgrade
Line 103: Line 42:
== Removing a Package == == 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).
Line 106: Line 49:
# aptitude remove <package>
}}}
where <package> is the name of the package (application) you want to remove.

To also delete files and directories created by the package after installation, such as configuration or status ('''Warning''': this may include files modified by the user), use:
{{{
# aptitude purge <package>
apt search <string>
Line 115: Line 52:
== Updating a Package == You may want to redirect the output into {{{less}}} (a scrollable viewer) since the list may be huge: {{{ apt search <string> | less }}}
Line 117: Line 54:
Open a root console
{{{
# aptitude upgrade <package>
}}}
where <package> is the name of the package (application) you want to update.
To search packages only by name you may use {{{dpkg-query -l '*<string>*'}}}
Line 123: Line 56:
== Keeping your system up-to-date == You can also find package information in the following directories:
Line 125: Line 58:
Open a root console
{{{
# aptitude update
# aptitude upgrade
}}}
This does all the "noninterfering" package upgrades.
 * {{{/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.
Line 132: Line 62:
{{{
# aptitude dist-upgrade
}}}
This does package upgrades that require installing or removing some other package. 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 "{{{man apt_preferences}}}") before doing the "{{{dist-upgrade}}}".
=== apt-file ===
Line 137: Line 64:
== Search for packages == 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.
Line 139: Line 66:
Open a console
{{{
$ apt-cache search <string>
}}} where <string> is a list of keywords to search for.
 * 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`
Line 144: Line 70:
You may want to pipe the output (redirect the output) into "less" (a scrollable viewer) since the list may be huge: === Online search using the Debian website ===
Line 146: Line 72:
{{{
$ apt-cache search <string> | less
}}}
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 152: Line 76:
Open a console 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 ==
Line 154: Line 91:
$ dpkg --list dpkg -L <package>
Line 156: Line 93:

== 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
}}}
Line 159: Line 170:
 * [[AptTools]] - Further Apt Tools
 * [[Synaptic]] - Graphical Apt System
 * [[Aptitude]] - Powerful ncurses-based Apt System
 * [[SecureApt]] - Cryptographic signatures
 * The main [[Apt]] wiki page
 * [[PackageManagement]]
 * [[PackageManagementTools]]

{{{#!wiki comment
Please place any links to Apt-related pages on the main Apt page, so that all can be found there
}}}
{{{#!wiki comment
The above comment seems not relevant anymore since Apt page is now very small and all info were moved elsewhere
}}}

Line 164: Line 183:
CategoryQuickPackageManagement | CategoryPackageManagement
CategoryPackageManagement | CategorySoftware

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