Linux: How to Install/Remove Packages

By Xah Lee. Date: . Last updated: .

Here's how to install and remove Ubuntu Linux software packages.

Install Package

Remove Package

Search package

Describe Package

List Installed Packages

Launch Software Update App

in terminal type update-manager

The regular run of update-manager is equivalent to:

# equivalent to typical running of the gui update-manager
sudo apt-get update
sudo apt-get upgrade
sudo apt-get distupgrade

Advanced Tech Detail

The following is more advanced topics.

Here's the basic tools and their relations.

For programers and sys-admins, you should just use “dpkg-*” and “apt-*” command line tools.

dpkg is a lower level program. Normally you shouldn't need to use it.

Be sure to read their man pages.

common usage of dpkg:

dpkg Tools

How to list all installed packages?

dpkg -l

sample output

◆ xah@xah-p6813w◆ 2013-06-02 20:23 ◆ ~
◆ dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                Version             Description
+++-===================-===================-======================================================
ii  abiword             2.9.2+svn20120213-1 efficient, featureful word processor with collaboratio
ii  abiword-common      2.9.2+svn20120213-1 efficient, featureful word processor with collaboratio
ii  abiword-plugin-gram 2.9.2+svn20120213-1 grammar checking plugin for AbiWord
ii  abiword-plugin-math 2.9.2+svn20120213-1 equation editor plugin for AbiWord
ii  accountsservice     0.6.15-2ubuntu9.6   query and manipulate user account information
ii  acl                 2.2.51-5ubuntu1     Access control list utilities
ii  acpi-support        0.140.1             scripts for handling many ACPI events
…

Package Status Flags

When doing dpkg --l, what does those “ii”, “un”, mean?

Those are package status flags.

dpkg --l and dpkg-query -l will list packages with status flags. Package status flags are the first 3 chars of each line. See man dpkg-query.

The first three columns of the output show
the desired action, the package status, and errors, in that order.

Desired action:
  u = Unknown
  i = Install
  h = Hold
  r = Remove
  p = Purge

Package status:
  n = Not-installed
  c = Config-files
  H = Half-installed
  U = Unpacked
  F = Half-configured
  W = Triggers-awaiting
  t = Triggers-pending
  i = Installed

Error flags:
  <empty> = (none)
  R = Reinst-required

How to list all packages available?

dpkg-query -l '*'

How to remove a package?

use dpkg --remove or dpkg --purge. “--remove” will delete the binary, “--purge” will also delete its conf files.

-r, --remove, -P, --purge package...|-a|--pending

Remove an installed package. -r or --remove remove everything except
conffiles. This may avoid having to reconfigure the package if it is
reinstalled later. (Conffiles are configura‐ tion files that are
listed in the DEBIAN/conffiles control file). -P or --purge removes
everything, including conffiles. If -a or --pending is given instead
of a package name, then all packages unpacked, but marked to be
removed or purged in file /var/lib/dpkg/status, are removed or purged,
respectively. Note: some configuration files might be unknown to dpkg
because they are created and handled separately through the
configuration scripts. In that case, dpkg won't remove them by itself,
but the package's postrm script (which is called by dpkg), has to take
care of their removal during purge. Of course, this only applies to
files in system directories, not configuration files written to
individual users' home directories.

Removing of a package consists of the following steps:

       1. Run prerm script

       2. Remove the installed files

       3. Run postrm script

Package status file location: /var/lib/dpkg/status

How to show package status?

dpkg-query -s package_name

◆ dpkg-query -s git
Package: git
Status: install ok installed
Priority: optional
Section: vcs
Installed-Size: 13684
Maintainer: Ubuntu Developers <a href="mailto:ubuntu-devel-discuss%40lists.ubuntu.com"><ubuntu-devel-discuss@lists.ubuntu.com></a>
Architecture: amd64
Version: 1:1.7.9.5-1
Replaces: cogito (<< 0.16rc2-0), git-core (<< 1:1.7.0.4-1.), gitweb (<< 1:1.7.4~rc1)
Provides: git-completion, git-core
Depends: libc6 (>= 2.14), libcurl3-gnutls (>= 7.16.2-1), libexpat1 (>= 1.95.8), zlib1g (>= 1:1.2.0), perl-modules, liberror-perl, git-man (>> 1:1.7.9.5), git-man (<< 1:1.7.9.5-.)
Recommends: patch, less, rsync, ssh-client
Suggests: git-daemon-run | git-daemon-sysvinit, git-doc, git-el, git-arch, git-cvs, git-svn, git-email, git-gui, gitk, gitweb
Breaks: cogito (<= 0.18.2+), git-buildpackage (<< 0.4.38), git-core (<< 1:1.7.0.4-1.), gitosis (<< 0.2+20090917-7), gitpkg (<< 0.15), gitweb (<< 1:1.7.4~rc1), guilt (<< 0.33), qgit (<< 1.5.5), stgit (<< 0.15), stgit-contrib (<< 0.15)
Conflicts: git-core (<< 1:1.5.2~rc3-2.)
Conffiles:
 /etc/bash_completion.d/git 8150253dd1e98e926da1dee7ee2253c6
Description: fast, scalable, distributed revision control system
 Git is popular version control system designed to handle very large
 projects with speed and efficiency; it is used for many high profile
 open source projects, most notably the Linux kernel.
 .
 Git falls in the category of distributed source code management tools.
 Every Git working directory is a full-fledged repository with full
 revision tracking capabilities, not dependent on network access or a
 central server.
 .
 This package provides the git main components with minimal dependencies.
 Additional functionality, e.g. a graphical user interface and revision
 tree visualizer, tools for interoperating with other VCS's, or a web
 interface, is provided as separate git* packages.
Original-Maintainer: Gerrit Pape <a href="mailto:pape%40smarden.org"><pape@smarden.org></a>
Homepage: http://git-scm.com/
◆ apt-cache show git
Package: git
Priority: optional
Section: vcs
Installed-Size: 13684
Maintainer: Ubuntu Developers <a href="mailto:ubuntu-devel-discuss%40lists.ubuntu.com"><ubuntu-devel-discuss@lists.ubuntu.com></a>
Original-Maintainer: Gerrit Pape <a href="mailto:pape%40smarden.org"><pape@smarden.org></a>
Architecture: amd64
Version: 1:1.7.9.5-1
Replaces: cogito (<< 0.16rc2-0), git-core (<< 1:1.7.0.4-1.), gitweb (<< 1:1.7.4~rc1)
Provides: git-completion, git-core
Depends: libc6 (>= 2.14), libcurl3-gnutls (>= 7.16.2-1), libexpat1 (>= 1.95.8), zlib1g (>= 1:1.2.0), perl-modules, liberror-perl, git-man (>> 1:1.7.9.5), git-man (<< 1:1.7.9.5-.)
Recommends: patch, less, rsync, ssh-client
Suggests: git-daemon-run | git-daemon-sysvinit, git-doc, git-el, git-arch, git-cvs, git-svn, git-email, git-gui, gitk, gitweb
Conflicts: git-core (<< 1:1.5.2~rc3-2.)
Breaks: cogito (<= 0.18.2+), git-buildpackage (<< 0.4.38), git-core (<< 1:1.7.0.4-1.), gitosis (<< 0.2+20090917-7), gitpkg (<< 0.15), gitweb (<< 1:1.7.4~rc1), guilt (<< 0.33), qgit (<< 1.5.5), stgit (<< 0.15), stgit-contrib (<< 0.15)
Filename: pool/main/g/git/git_1.7.9.5-1_amd64.deb
Size: 6086854
MD5sum: a280c48b41de227103e665c5d11a310a
SHA1: f60552319e5af79f019eb079e17b85c1d65c2c3a
SHA256: 115a2b4a6fc3f8f7709aebd6064e0ad01225330a5ddd5e0fff28e90efa8e9535
Description-en: fast, scalable, distributed revision control system
 Git is popular version control system designed to handle very large
 projects with speed and efficiency; it is used for many high profile
 open source projects, most notably the Linux kernel.
 .
 Git falls in the category of distributed source code management tools.
 Every Git working directory is a full-fledged repository with full
 revision tracking capabilities, not dependent on network access or a
 central server.
 .
 This package provides the git main components with minimal dependencies.
 Additional functionality, e.g. a graphical user interface and revision
 tree visualizer, tools for interoperating with other VCS's, or a web
 interface, is provided as separate git* packages.
Homepage: http://git-scm.com/
Description-md5: c1f968556452a190fe359bffd151c012
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
◆ apt-cache showpkg git
Package: git
Versions:
1:1.7.9.5-1 (/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_binary-amd64_Packages) (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_binary-amd64_Packages
                  MD5: c1f968556452a190fe359bffd151c012
 Description Language: en
                 File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_i18n_Translation-en
                  MD5: c1f968556452a190fe359bffd151c012

Reverse Depends:
  sparkleshare,git 1.7.1
  qtcreator,git
  pass,git
  git:i386,git
  vcsh,git
  undertaker,git
  tig,git 1:1.7.0.4-2~
  sparkleshare,git 1.7.1
  ruby-rvm,git
  qtcreator,git
  qgit,git
  mr,git 1:1.7
  libgit-wrapper-perl,git 1:1.7.0.4-2~
  libgit-repository-perl,git 1:1.7.0.4-2~
  libapp-nopaste-perl,git 1:1.7.0.4-2~
  kup-server,git
  kdevplatform5-libs,git
  kdesrc-build,git
  ikiwiki-hosting-web,git 1:1.7.0
  ikiwiki,git 1:1.7
  hobbit-plugins,git
  hg-fast-export,git
  guilt,git 1:1.8
  guilt,git 1:1.7
  gitweb,git 1:1.7.9.5-.
  gitweb,git 1:1.7.9.5
  gitstats,git 1:1.7
  gitpkg,git 1.7.0
  gitolite,git 1:1.7.0.4
  gitg,git
  gitalist-common,git
  git-svn,git 1:1.7.9.5-.
  git-svn,git 1:1.7.9.5
  git-stuff,git
  git-sh,git
  git-review,git
  git-gui,git 1:1.7.9.5-.
  git-gui,git 1:1.7.9.5
  git-flow,git
  git-email,git 1:1.7.9.5-.
  git-email,git 1:1.7.9.5
  git-el,git 1:1.7.4.1-2~
  git-el,git 1:1.7.4.1-2~
  git-el,git 1:1.7.4.1-2~
  git-dpm,git 1:0.7.1
  git-daemon-sysvinit,git 1:1.7.9.5-.
  git-daemon-sysvinit,git 1:1.7.9.5
  git-daemon-run,git 1:1.7.9.5-.
  git-daemon-run,git 1:1.7.9.5
  git-cvs,git 1:1.7.9.5-.
  git-cvs,git 1:1.7.9.5
  git-buildpackage,git 1:1.7.0.4-2
  git-arch,git 1:1.7.9.5-.
  git-arch,git 1:1.7.9.5
  git-annex,git 1:1.7.7
  git-all,git 1:1.7.9.5-.
  git-all,git 1:1.7.9.5
  giggle,git 1:1.5.6.3
  fusionforge-plugin-scmgit,git 1:1.7
  flashbake,git 1:1.7
  drush,git
  dh-make-perl,git
  commit-patch,git
  bzr-git,git
  bzr-fastimport,git
  bup,git 1:1.7.0.4-2
  mozilla-devscripts,git
  gitk,git 1:1.7.9.5-.
  gitk,git 1:1.7.9.5
  git-man,git 1:1.7.4~rc1
  git-man,git 1:1.7.4~rc1
  git-doc,git
  git-core,git 1:1.7.0.2
  etckeeper,git 1:1.7
  dh-ocaml,git
  autopoint,git 1:1.7.0.5
Dependencies:
1:1.7.9.5-1 - libc6 (2 2.14) libcurl3-gnutls (2 7.16.2-1) libexpat1 (2 1.95.8) zlib1g (2 1:1.2.0) perl-modules (0 (null)) liberror-perl (0 (null)) git-man (4 1:1.7.9.5) git-man (3 1:1.7.9.5-.) git-daemon-run (16 (null)) git-daemon-sysvinit (0 (null)) git-doc (0 (null)) git-el (0 (null)) git-arch (0 (null)) git-cvs (0 (null)) git-svn (0 (null)) git-email (0 (null)) git-gui (0 (null)) gitk (0 (null)) gitweb (0 (null)) patch (0 (null)) less (0 (null)) rsync (0 (null)) ssh-client (0 (null)) git-core (3 1:1.5.2~rc3-2.) git-core:i386 (3 1:1.5.2~rc3-2.) cogito (1 0.18.2+) cogito:i386 (1 0.18.2+) git-buildpackage (3 0.4.38) git-buildpackage:i386 (3 0.4.38) git-core (3 1:1.7.0.4-1.) git-core:i386 (3 1:1.7.0.4-1.) gitosis (3 0.2+20090917-7) gitosis:i386 (3 0.2+20090917-7) gitpkg (3 0.15) gitpkg:i386 (3 0.15) gitweb (3 1:1.7.4~rc1) gitweb:i386 (3 1:1.7.4~rc1) guilt (3 0.33) guilt:i386 (3 0.33) qgit (3 1.5.5) qgit:i386 (3 1.5.5) stgit (3 0.15) stgit:i386 (3 0.15) stgit-contrib (3 0.15) stgit-contrib:i386 (3 0.15) cogito (3 0.16rc2-0) cogito:i386 (3 0.16rc2-0) git-core (3 1:1.7.0.4-1.) git-core:i386 (3 1:1.7.0.4-1.) gitweb (3 1:1.7.4~rc1) gitweb:i386 (3 1:1.7.4~rc1) git:i386 (0 (null))
Provides:
1:1.7.9.5-1 - git-core git-completion
Reverse Provides:
◆ apt-cache showsrc git
Package: git
Binary: git, git-man, git-core, git-doc, git-arch, git-cvs, git-svn, git-email, git-daemon-run, git-daemon-sysvinit, git-gui, gitk, git-el, gitweb, git-all
Version: 1:1.7.9.5-1
Priority: optional
Section: vcs
Maintainer: Gerrit Pape <a href="mailto:pape%40smarden.org"><pape@smarden.org></a>
Build-Depends: libz-dev, libcurl4-gnutls-dev | libcurl3-gnutls-dev, libexpat1-dev, subversion, libsvn-perl | libsvn-core-perl, tcl8.5, gettext, cvs, cvsps, libdbd-sqlite3-perl, unzip, libio-pty-perl, dpkg-dev (>= 1.15.7~), libc6.1 (>= 2.10.2-6) [ia64]
Build-Depends-Indep: asciidoc (>> 8.0.0), xmlto, docbook-xsl (>> 1.72)
Architecture: any all
Standards-Version: 3.9.3.1
Format: 1.0
Directory: pool/main/g/git
Files:
 0f7b1cf3b3960c42d7376b69fb42dda8 1957 git_1.7.9.5-1.dsc
 094ddc0175d7c5112c7ac99ca7079882 3617300 git_1.7.9.5.orig.tar.gz
 5e6cd963d5d3136be043c1382e396dfc 491003 git_1.7.9.5-1.diff.gz
Uploaders: Jonathan Nieder <a href="mailto:jrnieder%40gmail.com"><jrnieder@gmail.com></a>
Homepage: http://git-scm.com/
Vcs-Browser: http://repo.or.cz/w/git/debian.git/
Vcs-Git: http://smarden.org/git/git.git/
Package-List:
 git deb vcs optional
 git-all deb vcs optional
 git-arch deb vcs optional
 git-core deb vcs optional
 git-cvs deb vcs optional
 git-daemon-run deb vcs optional
 git-daemon-sysvinit deb vcs extra
 git-doc deb doc optional
 git-el deb vcs optional
 git-email deb vcs optional
 git-gui deb vcs optional
 git-man deb doc optional
 git-svn deb vcs optional
 gitk deb vcs optional
 gitweb deb vcs optional
Checksums-Sha1:
 6e75c2506905882da350d8eaebd862c51c4aa8c2 1957 git_1.7.9.5-1.dsc
 33f5a5b0b6c8f8addbbec0b042731c44fd79f90c 3617300 git_1.7.9.5.orig.tar.gz
 77a4147891069d8a30c8568b9262cce3428a1195 491003 git_1.7.9.5-1.diff.gz
Checksums-Sha256:
 d95d819286ae240420020064c54f13e8ccc57733d75e9b8e3f37c944c0db29c1 1957 git_1.7.9.5-1.dsc
 3ddd52348c4b5212e63fbbe51bc6eccea0833a98d413034187c15037d1375759 3617300 git_1.7.9.5.orig.tar.gz
 a99342f6542ec59bdedd64da183a16d801e263c553cc738cd4b2fc6be9b47811 491003 git_1.7.9.5-1.diff.gz
◆ apt-cache depends git
git
  Depends: libc6
  Depends: libcurl3-gnutls
  Depends: libexpat1
  Depends: zlib1g
  Depends: perl-modules
  Depends: liberror-perl
  Depends: git-man
  Depends: git-man
 |Suggests: git-daemon-run
  Suggests: git-daemon-sysvinit
  Suggests: git-doc
  Suggests: git-el
  Suggests: git-arch
  Suggests: git-cvs
  Suggests: git-svn
  Suggests: git-email
  Suggests: git-gui
  Suggests: gitk
  Suggests: gitweb
  Recommends: patch
    patch:i386
  Recommends: less
  Recommends: rsync
    rsync:i386
  Recommends: <ssh-client>
    openssh-client
    openssh-client:i386
  Conflicts: git-core
  Conflicts: <git-core:i386>
  Breaks: <cogito>
  Breaks: <cogito:i386>
  Breaks: git-buildpackage
  Breaks: <git-buildpackage:i386>
  Breaks: git-core
  Breaks: <git-core:i386>
  Breaks: <gitosis>
  Breaks: <gitosis:i386>
  Breaks: gitpkg
  Breaks: <gitpkg:i386>
  Breaks: gitweb
  Breaks: <gitweb:i386>
  Breaks: guilt
  Breaks: <guilt:i386>
  Breaks: qgit
  Breaks: qgit:i386
  Breaks: stgit
  Breaks: <stgit:i386>
  Breaks: stgit-contrib
  Breaks: <stgit-contrib:i386>
  Replaces: <cogito>
  Replaces: <cogito:i386>
  Replaces: git-core
  Replaces: <git-core:i386>
  Replaces: gitweb
  Replaces: <gitweb:i386>
  Conflicts: git:i386

man sources.list

/etc/apt/sources.list

deb http://us.archive.ubuntu.com/ubuntu/ precise-updates restricted main multiverse universe

APT Commands

/var/cache/apt/archives/