≡ Menu

Debian Linux apt-get package management cheat sheet

Both Debian and Ubuntu Linux provides a number of package management tools. This article summaries package management command along with it usage and examples for you.

  • apt-get : APT is acronym for Advanced Package Tool. It supports installing packages over internet using ftp or http protocols. You can also upgrade all packages in a single operations, which makes it even more attractive.
  • dpkg : Debian packaging tool which can be use to install, query, uninstall packages.
  • Gui tools: You can also try GUI based or high level interface to the Debian GNU/Linux package system. Following list summaries them:

    • aptitude: It is a text-based interface to the Debian GNU/Linux package system.
    • synaptic: GUI front end for APT

Red hat Linux package names generally end in .rpm, similarly Debian package names end in .deb, for example:

apache_1.3.31-6_i386.deb

Where,

  1. apache : Package name
  2. 1.3.31-6 : Version number
  3. i386 : Hardware Platform on which this package will run (i386 == intel x86 based system)
  4. .deb : Extension that suggest it is a Debian package

Remember, whenever I refer .deb file it signifies complete file name, and whenever I refer package name it must be first part of .deb file. For example, when I refer to a package sudo it means sudo only and not the .deb file i.e. sudo_1.6.7p5-2_i386.deb. You can find out debian package name with the following command:

apt-cache search {package-name}
apt-cache search apache

Finally, most of the actions listed in this post are written with the assumption that they will be executed by the root user running the bash or any other modern shell.

apt-get add a new package

Add a new package called samba. The syntax is:

 
apt-get install {package-name}
 

To install a package called samba, run:

# apt-get install samba

apt-get remove the package called samba but keep the configuration files

The syntax is:

 
apt-get remove {package-name}
 

Example:

# apt-get remove samba

apt-get remove (erase) package and configuration file

The syntax is:

 
apt-get --purge remove {package-name}
 

Example:

# apt-get --purge remove samba

apt-get update (upgrade) package

The syntax is:

 
apt-get upgrade
 

To upgrade individual package called sudo, enter:
# apt-get install sudo

apt-get display available software updates

Following command will display the list of all available upgrades (updates) using -u option, if you decided to upgrade all of the shown packages just hit 'y'

# apt-get upgrade samba

However if you just wish to upgrade individual package then use apt-get command and it will take care of rest of your worries:

 
apt-get install {package-name}
 

dpkg command to get package information such as description of package, version etc.

The syntax is:

 
dpkg --info {.deb-package-name}
 

Example:

# dpkg --info sudo_1.6.7p5-2_i386.deb | less

List all installed packages

The syntax is:

dpkg -l

Example:

# dpkg -l

To list individual package try such as apache

# dpkg -l apache

You can also use this command to see (verify) if package sudo is install or not (note that if package is installed then it displays package name along with small description):

# dpkg -l | grep -i 'sudo'

To list packages related to the apache:

# dpkg -l '*apache*'

List files provided (or owned) by the installed package (for example what files are provided by the installed samba package). The syntax is:

 
dpkg -L {package-name}
 

Example:

# dpkg -L samba

(H) List files provided (or owned) by the package (for example what files are provided by the uninstalled sudo package). The syntax is:

 
dpkg --contents {.deb-package-name}
 

Example:

# dpkg --contents sudo_1.6.7p5-2_i386.deb

Find, what package owns the file /bin/netstat?

The syntax is:

 
dpkg -S {/path/to/file}
 

Example:

# dpkg -S /bin/netstat

Search for package or package description

Some times you don't know package name but aware of some keywords to search the package. Once you got package name you can install it using apt-get -i {package-name} command:

 
apt-cache search "Text-to-search"
apt-cache search "httpd"
apt-cache search "web server"
apt-cache search "web server"| grep something
 

Find out all the Debian package which can be used for Intrusion Detection

Type the following command:

# apt-cache search "Intrusion Detection"

Find out all sniffer packages, run:

# apt-cache search sniffer

Find out if Debian package is installed or not (status)

The syntax is:

 
dpkg -s {package-name} |  grep Status
 

Example:

# dpkg -s samba| grep Status

List each dependency a package has...

Display a listing of each dependency a package has and all the possible other packages that can fulfill that dependency. You hardly use this command as apt-get does decent job fulfill all package dependencies. The syntax is:

 
apt-cache depends package
 

Display dependencies for lsof and mysql-server packages:

# apt-cache depends lsof
# apt-cache depends mysql-server

Further reading

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 20 comments… add one }

  • Anonymous May 14, 2005, 11:25 am

    What is wrong with command?
    dpkg -S /etc/passwd

    It should give me hint about the .deb file that what package owns the file /etc/passwd file…

  • LinuxTitli May 14, 2005, 6:15 pm

    Because file /etc/passwd created by the script which was executed by apt-get install pkg.deb command …

  • Anonymous July 21, 2005, 10:03 am

    slight typo, para 5 above…
    Redhat packages end with ‘.rpm’ and NOT ‘.rmp’ as stated.

  • Rock Da Linux July 21, 2005, 1:36 pm

    >slight typo, para 5 above…
    Redhat packages end with ‘.rpm’ and NOT ‘.rmp’ as stated.

    Thanks for pointing it out. Typo is corrected.

  • Jissouille December 19, 2008, 7:51 pm

    Be careful when using this command :
    dpkg -l | grep -i 'sudo'

    because dpkg’s output depends on the width of the terminal. For example compare :
    dpkg -l '*excel-perl*'
    and
    dpkg -l |grep '*excel-perl*'

    To obtain the “wide” listing (and thus be able to safely use pipes) you can use :
    COLUMNS=200 dpkg -l '*excel-perl*'

  • Ryan April 16, 2009, 4:51 pm

    Why use apt-get, dpkg, etc. when aptitude does all this and more?

  • kneekoo August 16, 2009, 11:19 pm

    Because it’s way easier to type: apt-get install apache2 php5 mysql than enter aptitude and select the packages then install. When you know how… it’s easier with apt-get.

    • klm August 18, 2010, 8:44 am

      i find that aptitude and apt-get uses the same command-line syntax. i believe the only difference is that aptitude does better logging and search-formats are better.

  • muhammad zia ul haq October 22, 2009, 1:01 am

    how to install a new package downloaded and stored in the flash disk, the package. deb

    ….^_^ thank’s

  • kneekoo October 22, 2009, 8:21 am

    dpkg -i package_name.deb

    Or if you have more deb files and you want to install them all at once:

    dpkg -i *.deb

  • J Story November 12, 2009, 9:19 pm

    Is there no way to upgrade an installed package to a downloaded .deb file?

    This is kindergarten stuff for .rpm systems, but google gives me no joy here.

  • debmonkey December 30, 2009, 2:43 pm

    Aptitude has command line mode as well as gui.

    aptitude install apache

    does exactly that. About the only time to use apt-get these days is to install aptitude. ;)

  • gwern March 1, 2010, 10:19 pm

    J Story: does ‘sudo dpkg -i foo.deb’ not work or something?

  • narendra sisodiya December 6, 2010, 6:57 pm

    I want to include this article in School OS Distro – http://schoolos.org , may I ?

  • Jimmy April 12, 2011, 8:56 pm

    **J Story November 12, 2009
    Is there no way to upgrade an installed package to a downloaded .deb file?

    This is kindergarten stuff for .rpm systems, but google gives me no joy here.**

    I know that you can do a dpkg -i –force-overwrite (packagename.deb) and that will overwrite an existing installation.

  • ROBERT WATKINS August 8, 2011, 8:19 pm

    please tell me where do i find the url to type :sudo apt -get install afce4? THANK YOU,,,BOB WATKINS,,,watkinsbob5@yahoo.com

  • Lee April 12, 2012, 8:30 pm

    aptitude install apache2 php5 mysql
    Same syntax.

    From a message by Joey Hess on a Debian User List entry:
    http://lists.debian.org/debian-devel/2003/07/msg02135.html

    Seven reasons why you should be using aptitude instead of apt-get.

    1. aptitude can look just like apt-get

    If you run ‘aptitude update’ or ‘aptitude upgrade’ or ‘aptitude
    install’, it looks and works just like apt-get, with a few enhancements.
    So there is no learning curve.

    2. aptitude sanely handles recommends

    A long-standing failure of apt-get has been its lack of support for
    the Recommends relationship. Which is a problem because many packages
    in Debian rely on Recommends to pull in software that the average user
    generally uses with the package. This is a not uncommon cause of
    trouble, even though apt-get recently became able to at least mention
    recommended packages, it’s easy to miss its warnings.

    Aptitude supports Recommends by default, and can be confgigured to
    support Suggests too. It even supports installing recommended packages
    when used in command-line mode.

    3. aptitude tracks automatically installed packages

    Stop worrying about pruning unused libraries and support packages from
    your system. If you use aptitude to install everything, it will keep
    track of what packages are pulled in by dependencies alone, and remove
    those packages when they are no longer needed.

    4. use aptitude as a normal user and avoid hosing your system

    Maybe you didn’t know that you can run aptitude in gui mode as a regular
    user. Make any changes you’d like to try out. If you get into a real
    mess, you can hit ‘q’ and exit, your changes will not be saved.
    (aptitude also lets you use ctrl-u to undo changes). Since it’s running
    as a normal user, you cannot hose your system until you tell aptitude to
    do something, at which point it will prompt you for your root password.

    5. aptitude has a powerful UI and searching capabilities

    Between aptitude’s categorical browser and its great support for
    mutt-style filtering and searching of packages by name, description,
    maintainer, dependencies, etc, you should be able to find packages
    faster than ever before using aptitude.

    6. aptitude makes it easy to keep track of obsolete software

    If Debian stops distributing a package, apt will leave it on your system
    indefinitly, with no warnings, and no upgrades. Aptitude lists such
    packages in its “Obsolete and Locally Created Packages” section, so you
    can be informed of the problem and do something about it.

    7. aptitude has an interface to the Debian task system

    Aptitude lets you use Debian’s task system as it was designed to be
    used. You can browse the available tasks, select a task for install, and
    then dig into it and de-select parts of the task that you don’t want.
    apt-get has no support for tasks, and aptitude is better even than
    special purpose tools like tasksel.

  • bruno & bronko July 30, 2012, 1:33 pm

    what about:
    apt-get -s upgrade
    -s option simulates and apt-get action
    can be handy at times

  • zipizap December 4, 2013, 2:08 pm

    Sharing my dpkg cheat-sheet, in case its usefull :)

    https://raw.github.com/zipizap/LPIC-1-resume-diagrams/master/dpkg_resume.png

  • kneekoo December 5, 2013, 5:50 am

    zipzap: Useful. Thanks! :)

Leave a Comment