Differences between revisions 1 and 62 (spanning 61 versions)
Revision 1 as of 2005-09-03 20:53:55
Size: 3553
Editor: ?DavidRichardBell
Comment:
Revision 62 as of 2019-08-13 18:44:42
Size: 5542
Editor: nodiscc
Comment: Move intro to SourcesLIst page
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#language en
~-[[DebianWiki/EditorGuide#traduction|Translation(s)]]: English - [[fr/AptCLI|Français]] - [[it/AptCLI|Italiano]] - [[AptCLIDutch|Nederlands]] - [[ko/AptCLI|한국어(Korean)]]-~
----
Line 3: Line 6:
[[TableOfContents([3])]] <<TableOfContents(3)>>
Line 5: Line 8:
== 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 [[terminal|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 20: Line 12:
You should read the manual for this configuration file first - type "man apt-get" at a console window.
Line 22: Line 13:
__Use apt-setup__ == Installing, removing and upgrading packages ==
Line 24: Line 15:
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. 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:
{{{1. Open a root console/terminal window (Applications -> System Tools-> Root Terminal in GNOME)
2. Type "apt-setup" (as root)
3. Follow the Wizard!
}}}
Replace {{{<package>}}} with the name of the package you want to act on.
Line 31: Line 19:
__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 60: 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"}}}

==Search for packages==

{{{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.}}}

You may want to pipe the output (redirect the output) into "less" (a scrollable viewer) since the list may be huge:
To upgrade all packages without removing any (''safe'' upgrade):
Line 72: Line 31:
apt-cache search <string> | less
}}}
apt update
apt upgrade
}}}
Line 75: Line 35:
==List installed packages== 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 77: Line 37:
{{{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")}}}
{{{
apt dist-upgrade
}}}
Line 81: Line 41:
==Further Reading==
Line 83: Line 42:
See: ["AptTools"]
See: ["Synaptic"]
== Search for packages ==

In addition to the tools mentioned above, you can also use the {{{apt-cache}}} command to search for packages.

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-cache 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.

== 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, use `which myprogram`

== Further Reading ==

 * Back to the main [[Apt]] wiki page

{{{#!wiki comment
Please place any links to Apt-related pages on the main Apt page, so that all can be found there
}}}

----
CategoryQuickPackageManagement | CategoryPackageManagement

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


This page describes how to use various CLI (command line interface) Apt 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.

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.

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-cache 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.

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, use which myprogram

Further Reading

  • Back to the main Apt wiki page


?CategoryQuickPackageManagement | CategoryPackageManagement