Differences between revisions 56 and 57
Revision 56 as of 2019-02-24 16:23:37
Size: 5350
Editor: nodiscc
Comment: syntax fix
Revision 57 as of 2019-02-24 16:25:38
Size: 5312
Editor: nodiscc
Comment: Use DebianMan macro
Deletions are marked like this. Additions are marked like this.
Line 22: Line 22:
You should read the manual for this configuration file first [[https://manpages.debian.org/stretch/apt/sources.list.5.en.html|here]] or by typing {{{man sources.list}}} at a console window. You could also read the [[SourcesList|sources.list]] wiki page. You should read the manual for this configuration file first [[DebianMan:5/sources.list|here]] or by typing {{{man sources.list}}} at a console window. You could also read the [[SourcesList|sources.list]] wiki page.

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


This page describes how to use various CLI (command line interface) Apt tools.

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 3 DVDs (for the current Debian Stretch release).

Editing sources directly

You can edit the file which determines your sources directly using your favorite text editor. This example uses nano:

nano /etc/apt/sources.list

You should read the manual for this configuration file first here or by typing man sources.list at a console window. You could also read the sources.list wiki page.

These commands must be run as root. 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.

Using a graphical program

Some programs allow configuring Apt sources through a graphical interface. For example:

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}')

Further Reading

  • Back to the main Apt wiki page


?CategoryQuickPackageManagement | CategoryPackageManagement