APT Cheat Sheet | Packagecloud Blog (2024)

APT" stands for "Advanced Package Tool." APT is a package management system used by Debian and its derivatives, such as Ubuntu, to handle the installation, upgrade, and removal of software packages. It simplifies the process of managing software on Unix-like operating systems by automatically resolving dependencies, retrieving packages from repositories, and configuring the packages.

APT was designed to work with Debian's .deb packages, and it uses repositories where packages are stored, allowing users to search, install, or remove software easily. APT also has a command-line interface (apt-get, apt-cache) and other front-end tools like Synaptic Package Manager, which provides a graphical user interface for package management.

What does APT do?

APT is a set of core tools found inside the Debian operating system. It provides utilities for the installation and removal of software packages and dependencies on a system.

  • APT is a powerful tool that can be used to manage software packages on Debian-based systems.
  • APT can be used to install, remove, upgrade, and downgrade software packages.
  • APT can also be used to manage dependencies between packages.
  • APT is a valuable tool for any system administrator who needs to manage software packages on a Debian-based system.

apt-get / high level package handling utility

apt-getis the command-line tool for handling packages and provides functions such as installing, removing, and updating packages on a system with a single operation. We’ll cover the following commands forapt-get:

  • installand--reinstall
  • remove
  • purgeor--purge
  • upgrade
  • update
  • cleanandautoclean

apt-cache / high level package query utlity

apt-cacheprovides an interface to perform read-only operations on the APT package cache.apt-cachedoes not change the state of the system, but allows the user to extract useful information from package metadata.

We’ll go over the following commands forapt-cache:

  • pkgnames
  • searchshow

dpkg / low level package manager for Debian

dpkgis a tool for installing, removing, and querying individual packages. We’ll investigate some common commands and go over some basic usage ofdpkgin a couple of real-world examples.

  • --listor-l
  • --install
  • --remove
  • --purge
  • --update
  • --contents

apt-gethigh level package handling utility

Installing a Debian package:

 $ sudo apt-get install [package-name]

apt-getwants you to pass the[package-name]you wish to install, for example:

 $ sudo apt-get install vim

Removing a Debian package:

The following will remove a packagewithoutremoving its configuration files:

 $ sudo apt-get remove [package-name]

To remove a packageandits configuration files, usepurge:

 $ sudo apt-get purge [package-name]

or alternatively, use the--purgeflag on the remove command:

 $ sudo apt-get --purge remove [package-name]

Update package index files from sources.list:

 $ sudo apt-get update

When this command is run, all available packages are fetched and re-indexed from the locations specified in/etc/apt/sources.listand/etc/apt/sources.list.d/.

Upgrade all Debian system packages:

 $ sudo apt-get upgrade

This command installsallof the latest versions of each package installed on the system and is, generally, not recommended to be run on production systems.

Update / Reinstall a single package:

Once you’ve runapt-get updateto update repository metadata, you can update an installed package by runningapt-get install

 $ sudo apt-get install [package-name]

If you need to force reinstall a package, just pass the--reinstallflag

 $ sudo apt-get --reinstall install [package-name]

By passing the--reinstallflag, you will effectively force the package to be reinstalled even if it’s already installed and at the latest version. This will completely remove the package from the system* and reinstall it.

*Packages that depend on the[package-name]being reinstalled will not be removed from the system

APT cache files:

APTs cached files are located in:

  • /var/cache/apt/archives/

Clear the APT cache:

 $ sudo apt-get clean

Thecleancommand clears out the local repository of downloaded package files. It removes everythingexceptthepartials folderandlock filefrom/var/cache/apt/archives/.

Useapt-get cleanto free up disk space when necessary, or as part of regularly scheduled maintenance.

Remove useless files from the APT cache:

 $ sudo apt-get autoclean

autocleanis another method used to clear out the local repository of downloaded package files, just likeclean. The difference betweencleanandautocleanis that the latter only removes package files that can no longer be downloaded from their sources, and are very likely to be useless.

apt-cachehigh level package query utility

List all available packages:

 $ apt-cache pkgnames

This command will output a list of available package names for your system:

...aspell-bg389-ds-console-doclibreoffice-l10n-galibindicate-doclibreadline-devlibpng12-dev

Searching for a specific Debian package:

 $ apt-cache search [package-name-pattern]

This is really useful in case you don’t know the exact[package-name], but rather a description of what that package does; for example “Network Security”:

 $ apt-cache search "Network Security"

This will return a list of packages containing the string “Network Security” in the package description. Using apt-cache will look in thename,description, andprovidesfields of the available packages by default.

libnss3 - Network Security Service librarieslibnss3-1d - Network Security Service librarieslibnss3-dbg - Debugging symbols for the Network Security Service librarieslibnss3-dev - Development files for the Network Security Service librariescoolkey - Smart Card PKCS #11 cryptographic moduledaemonlogger - simple network packet logger and soft tap daemongrepcidr - Filter IP addresses matching IPv4 CIDR/network specificationhlbrw - assistant to help make new rules to HLBRlibjss-java - Network Security Services for Javalibnss3-tools - Network Security Service toolslibopenvas2 - remote network security auditor - shared librarieslibopenvas2-dev - remote network security auditor - static libraries and headersopenvas-client - Remote network security auditor, the clientopenvas-plugins-base - remote network security auditor - basic pluginsopenvas-plugins-dfsg - remote network security auditor - pluginsopenvas-server - remote network security auditor - serveropenvas-server-dev - remote network security auditor - static libraries and headerspython-nss - Python bindings for Network Security Services (NSS)scute - OpenPGP smartcard plugin for Mozilla Network Security Services

Show Debian package information:

 $ apt-cache show [package-name]

This will show apt metadata for the[package-name]given. This is an example using the “screen” package:

 $ apt-cache show screen

will output:

Package: screenPriority: optionalSection: miscInstalled-Size: 1052Maintainer: Ubuntu Developers <[email protected]>Original-Maintainer: Jan Christoph Nordholz <[email protected]>Architecture: amd64Version: 4.0.3-14ubuntu8Depends: libc6 (>= 2.4), libncursesw5 (>= 5.6+20070908), libpam0g (>= 0.99.7.1), dpkg (>= 1.15.4) | install-info, upstart-jobSuggests: byobuFilename: pool/main/s/screen/screen_4.0.3-14ubuntu8_amd64.debSize: 611204MD5sum: b5e98bb56fdfc9bf9fd13e6f726c83aaSHA1: 8d3e5c5d858b4a314a66b5bc51b3a557b85ea96cSHA256: 2b6c752fc226ad6e2e32cd93f089bf2a89d51e95f6e5ff1e7ed63b0b57ff592fDescription-en: terminal multiplexor with VT100/ANSI terminal emulation screen is a terminal multiplexor that runs several separate "screens" on a single physical character-based terminal. Each virtual terminal emulates a DEC VT100 plus several ANSI X3.64 and ISO 2022 functions. Screen sessions can be detached and resumed later on a different terminal. . Screen also supports a whole slew of other features. Some of these are: configurable input and output translation, serial port support, configurable logging, multi-user support, and utf8 charset support.Homepage: http://savannah.gnu.org/projects/screenDescription-md5: 031a852784c43a4c757fecf6b610c93eBugs: https://bugs.launchpad.net/ubuntu/+filebugOrigin: UbuntuSupported: 5yTask: cloud-image, ubuntu-usb, server, edubuntu-usb, edubuntu-desktop-kde, edubuntu-desktop-gnome

NOTE: Installed-Size and Size are returned in bytes -link to discussion

dpkglow level package manager for Debian

Install a package:

 dpkg -i [/path/to/vim_7.3.429-2ubuntu2_amd64.deb]

or alternatively, use the--installflag

 dpkg --install [/path/to/vim_7.3.429-2ubuntu2_amd64.deb]

Remove a package:

To remove a package usingdpkgwithoutremoving its configuration files:

 $ dpkg --remove [package-name]

alternatively, use the-rflag:

 $ dpkg -r [package-name]

To remove a package usingdpkgalong withits corresponding configuration files, use the--purgecommand:

 $ dpkg --purge [package-name]

List available system packages:

dpkg -lallows you to list a set of packages on the system and the state of those packages:

 $ dpkg -l [package-name-pattern]

You can use a regular expression to list information about all matching package names. For example:

 $ dpkg -l "re*"

will return all packages starting with the letters “re”:

||/ Name Version Description+++-==========================-==========================-====================================================================un readahead <none> (no description available)ii readline-common 6.2-8 GNU readline and history libraries, common filesun rebuildd <none> (no description available)un redhat-cluster-modules <none> (no description available)ii redis 2.8.3-1 redisun regina-normal-dev <none> (no description available)ii reprepro 4.8.2-1ubuntu0.1 Debian package repository producerii resolvconf 1.63ubuntu15 name server information handler

The first column shows the state of the package. You can learn more about package states by reading the dpkg man page:man 1 dpkg.

If the[package-name-pattern]is omitted fromdpkg -lthen all packages in/var/lib/dpkg/statuswill be listed, excluding packages that have been marked not-installed

 $ dpkg -l

will output something like:

...ii libxml2 2.7.8.dfsg-5.1ubuntu4.11 GNOME XML libraryii libxml2-dbg 2.7.8.dfsg-5.1ubuntu4.11 Debugging symbols for the GNOME XML libraryii libxml2-dev 2.7.8.dfsg-5.1ubuntu4.11 Development files for the GNOME XML libraryii libxmuu1 2:1.1.0-3 X11 miscellaneous micro-utility libraryii libxrender1 1:0.9.6-2ubuntu0.1 X Rendering Extension client libraryii libxslt1-dev 1.1.26-8ubuntu1.3 XSLT 1.0 processing library - development kitii libxslt1.1 1.1.26-8ubuntu1.3 XSLT 1.0 processing library - runtime libraryii libyaml-0-2 0.1.4-2 Fast YAML 1.1 parser and emitter libraryii libyaml-dev 0.1.4-2 Fast YAML 1.1 parser and emitter library (development)ii linux-firmware 1.79 Firmware for Linux kernel driversii linux-image-3.2.0-29-virtu 3.2.0-29.46 Linux kernel image for version 3.2.0 on 64 bit x86 Virtual Guestsii linux-image-virtual 3.2.0.29.31 Linux kernel image for virtual machinesii linux-libc-dev 3.2.0-37.58 Linux Kernel Headers for development...

List files in a package:

dpkg maintains a list of packages that are installed on a system in/var/lib/dpkg.

You can query the files in an installed package usingdpkg -L:

 $ dpkg -L [package-name]

So, for example:

 $ dpkg -L redis

returns the following results:

/./usr/usr/share/usr/share/doc/usr/share/doc/redis/usr/share/doc/redis/copyright/usr/share/doc/redis/changelog.Debian.gz/usr/bin/usr/bin/redis-check-dump/usr/bin/redis-benchmark/usr/bin/redis-server/usr/bin/redis-check-aof/usr/bin/redis-cli

If you’d like to list the files in a debian package that you’ve downloaded (but not installed), you can use the--contentsflag.

For example:

 $ dpkg --contents /path/to/redis_2.8.3-1_amd64.deb

returns the following results:

drwxr-xr-x root/root 0 2014-07-24 09:52 ./drwxr-xr-x root/root 0 2014-07-24 09:52 ./usr/drwxr-xr-x root/root 0 2014-07-24 09:52 ./usr/share/drwxr-xr-x root/root 0 2014-07-24 09:52 ./usr/share/doc/drwxr-xr-x root/root 0 2014-07-24 09:52 ./usr/share/doc/redis/-rw-r--r-- root/root 0 2014-07-24 09:52 ./usr/share/doc/redis/copyright-rw-r--r-- root/root 139 2014-07-24 09:52 ./usr/share/doc/redis/changelog.Debian.gzdrwxr-xr-x root/root 0 2014-07-24 09:52 ./usr/bin/-rwxr-xr-x root/root 22616 2014-07-24 09:52 ./usr/bin/redis-check-dump-rwxr-xr-x root/root 285712 2014-07-24 09:52 ./usr/bin/redis-benchmark-rwxr-xr-x root/root 844496 2014-07-24 09:52 ./usr/bin/redis-server-rwxr-xr-x root/root 10320 2014-07-24 09:52 ./usr/bin/redis-check-aof-rwxr-xr-x root/root 320432 2014-07-24 09:52 ./usr/bin/redis-cli

When the--contentsflag is used,dpkgcalls down to an action provided by another tooldpkg-deb, which provides tools to manipulate a debian package archive.

Show packages containing a filename or filepath:

 $ dpkg -S [filename-search-pattern]

For example, passing a specific filepath:

 $ dpkg -S /usr/share/man/man5

will return all the package names that contain that file path.

libc-bin, libarchive-dev, ntp, libpam-modules, libpam-runtime, initscripts, upstart, mount,libx11-data, fontconfig-config, isc-dhcp-client, isc-dhcp-common, rsyslog, sudo, ucf,collectd-core, libwrap0, openssl, openssh-client, rsync, module-init-tools, ncurses-bin,procps, login, nfs-common, cryptsetup, git-man, man-db, cron, libmagic1, libldap-2.4-2,libtirpc1, libnfsidmap2, adduser, resolvconf, dpkg, e2fsprogs, ifupdown, initramfs-tools,locales, kbd, openssh-server, apt, wireless-regdb, util-linux, passwd, mime-support, net-tools,manpages, dpkg-dev: /usr/share/man/man5

Show package information:

You can show package metadata of installed packages by usingdpkg -s:

 $ dpkg -s [package-name]

for example, the following command:

 $ dpkg -s screen

returns the package metadata:

Package: screenStatus: install ok installedPriority: optionalSection: miscInstalled-Size: 1052Maintainer: Ubuntu Developers <[email protected]>Architecture: amd64Version: 4.0.3-14ubuntu8Depends: libc6 (>= 2.4), libncursesw5 (>= 5.6+20070908), libpam0g (>= 0.99.7.1), dpkg (>= 1.15.4) | install-info, upstart-jobSuggests: byobuConffiles: /etc/screenrc 12c245238eb8b653625bba27dc81df6a /etc/init/screen-cleanup.conf 441f4a1c5b41d7f23427be5aa6ccbbccDescription: terminal multiplexor with VT100/ANSI terminal emulation screen is a terminal multiplexor that runs several separate "screens" on a single physical character-based terminal. Each virtual terminal emulates a DEC VT100 plus several ANSI X3.64 and ISO 2022 functions. Screen sessions can be detached and resumed later on a different terminal. . Screen also supports a whole slew of other features. Some of these are: configurable input and output translation, serial port support, configurable logging, multi-user support, and utf8 charset support.Homepage: http://savannah.gnu.org/projects/screenOriginal-Maintainer: Jan Christoph Nordholz <[email protected]>

Here are some additional tips for using APT and its related tools:

  • Use the apt-cache show command to view information about a package, such as its version, description, and dependencies.

  • Use the apt-cache search command to search for packages by name or keyword.

  • Use the apt-get install command to install a package.

  • Use the apt-get remove command to remove a package.

  • Use the apt-get update command to update the list of available packages.

  • Use the apt-get upgrade command to upgrade all installed packages to the latest version.

  • Use the apt-get dist-upgrade command to upgrade all installed packages, including removing and installing packages as needed.

  • Use the apt-get autoremove command to remove packages that are no longer needed.

  • Use the apt-get clean command to remove downloaded package files.

  • Use the apt-get autoclean command to remove downloaded package files that are no longer needed.

Conclusion

Getting more familiar with your package manager’s tools can help you be more productive when finding, installing, and querying packages.
We highly recommend that users of production Debian and Ubuntu systems become familiar withapt-get,apt-cache, anddpkg.

You can learn more about the tools mentioned in this blog post by reading the man pages as well.

APT Cheat Sheet | Packagecloud Blog (2024)
Top Articles
Who We Are-Alaska Permanent Fund Corporation
Security at N26
Will Byers X Male Reader
Lakers Game Summary
Live Basketball Scores Flashscore
EY – все про компанію - Happy Monday
Dr Klabzuba Okc
Computer Repair Tryon North Carolina
More Apt To Complain Crossword
Rubfinder
CSC error CS0006: Metadata file 'SonarAnalyzer.dll' could not be found
Edgar And Herschel Trivia Questions
Theycallmemissblue
Jc Post News
272482061
Jackson Stevens Global
Spoilers: Impact 1000 Taping Results For 9/14/2023 - PWMania - Wrestling News
E22 Ultipro Desktop Version
Energy Healing Conference Utah
라이키 유출
Brbl Barber Shop
Naya Padkar Gujarati News Paper
Best Middle Schools In Queens Ny
Dr Seuss Star Bellied Sneetches Pdf
Cinema | Düsseldorfer Filmkunstkinos
Jazz Total Detox Reviews 2022
Toonkor211
Rock Salt Font Free by Sideshow » Font Squirrel
What Is Xfinity and How Is It Different from Comcast?
Uhaul Park Merced
Maybe Meant To Be Chapter 43
Tenant Vs. Occupant: Is There Really A Difference Between Them?
Samsung 9C8
Space Marine 2 Error Code 4: Connection Lost [Solved]
Midsouthshooters Supply
Body Surface Area (BSA) Calculator
Elisabeth Shue breaks silence about her top-secret 'Cobra Kai' appearance
Trizzle Aarp
Craigslist Pets Plattsburgh Ny
Clima De 10 Días Para 60120
Cocaine Bear Showtimes Near Cinemark Hollywood Movies 20
Sofia Franklyn Leaks
Air Sculpt Houston
Richard Mccroskey Crime Scene Photos
Mmastreams.com
Phunextra
Runescape Death Guard
라이키 유출
Lorcin 380 10 Round Clip
How to Choose Where to Study Abroad
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5557

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.