Differences between revisions 6 and 71 (spanning 65 versions)
Revision 6 as of 2005-10-09 19:12:39
Size: 3697
Editor: ?SvenOlofsson
Comment:
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 1: Line 1:
This page describes how to use various CLI (command line interface) Apt tools. #language en
~-[[DebianWiki/EditorGuide#traduction|Translation(s)]]: English - [[fr/AptCLI|Français]] - [[it/AptCLI|Italiano]] - [[nl/AptCLI|Nederlands]] - [[ko/AptCLI|한국어(Korean)]]-~
----
Line 3: Line 5:
[[TableOfContents([3])]] This page describes how to use various [[CommandLineInterface|command line interface]] [[PackageManagementTools|package management tools]].
Line 5: Line 7:
http://www.vanadac.com/~dajhorn/projects/lmsw/10%20Spam/01%20apt-get%20install%20perlstuff.png <<TableOfContents(3)>>
Line 7: Line 9:
== 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:

{{{1. Open a root console/terminal window (Applications -> System Tools-> Root Terminal in GNOME)
2a. Type "nano /etc/apt/sources.list"
     - or -
2b. Type "gedit /etc/apt.sources.list"
3. Edit!
{{{#!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 22: Line 13:
You should read the manual for this configuration file first - type "man apt-get" at a console window. == Installing, removing and upgrading packages ==
Line 24: Line 15:
__Use apt-setup__ 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.
Line 26: Line 17:
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"] wizard. In the commands below, replace {{{<package>}}} with the name of the package you want to act on.
Line 28: Line 19:
{{{1. Open a root console/terminal window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-setup" (as root)
3. Follow the Wizard!
}}}

__Use 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:

{{{
1. Open a root console window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-get install apt-spy"
3. Read about how to use apt-spy: type "man apt-spy"
}}}

== Installing Packages ==

{{{1. Open a root console window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-get install <package>" where package is the name of the package (application) you want to install.}}}

== Removing a Package ==

{{{1. Open a root console window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-get remove <package>" where package is the name of the package (application) you want to remove.}}}

== Updating a Package ==

{{{1. Open a root console window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-get update <package>" where package is the name of the package (application) you want to update.}}}
 * 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>}}}
Line 62: Line 28:
{{{1. Open a root console window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-get update".
3. Type "apt-get dist-upgrade"}}}
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
}}}
Line 68: Line 44:
{{{1. Open a console window (Applications -> System Tools-> Terminal in GNOME)
2. Type "apt-cache search <string>" where <string> is the pattern to search for.}}}
In addition to the tools mentioned above, you can also use the {{{apt-cache}}} command to search for packages, or apt as described here.
Line 71: Line 46:
You may want to pipe the output (redirect the output) into "less" (a scrollable viewer) since the list may be huge: In the commands below, replace {{{<string>}}} with a list of keywords to search for (in package names or descriptions).
Line 74: Line 49:
apt-cache search <string> | less
}}}
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 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 79: Line 76:
{{{1. Open a console window (Applications -> System Tools-> Terminal in GNOME)
2. Type "dpkg --list"
3. You may want to pipe (redirect) that to a program called "less" since the list will be long (type "dpkg --list | less")}}}
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
}}}
Line 85: Line 170:
 * ["AptTools"] - Further Apt Tools
 * ["Synaptic"] - Graphical Apt System
 * 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
}}}


----

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