AptGet/Howto – Community Help Wiki – Ubuntu Documentation

This article applies to all supported versions

of Ubuntu package management via apt-get run hand in hand with the /etc/apt/sources.list file. For information about editing or updating the font list, see SourcesList.


This page describes how to handle packages on your system using apt-get and related commands. For example, you can install a new package, remove an installed package, or upgrade all installed packages to the latest versions.

  • Commands Example:

    sudo apt-get install ubuntu-desktop Installation commands

apt-get install <package_name> This command installs

  • a new package. apt-get build-dep <package_name>
  • This command searches the repositories and installs build dependencies for <package_name>. If the package is not in the repositories, it will return an error.

  • aptitude install <package_name>

    Aptitude is an Ncurses viewer of installed or available packages. Aptitude can be used from the command line in a similar way to apt-get. Enter the man’s aptitude for more information.

  • APT and aptitude will accept multiple package names as a space-delimited list. For example: apt-get install <package1_name> <package2_name> <package3_name>

auto-apt auto-apt run <command_string> This command is run <command_string> under the control of auto-apt

  • . If a program tries to access a file that is known to belong to an uninstalled package, auto-apt will install that package using apt-get. This feature requires apt and sudo to work.

  • Auto-apt maintains databases that must be kept up to date for it to be effective. This is accomplished by calling the auto-apt update, auto-apt updateb, and auto-apt update-local commands.
  • Example of use
    • You’ are compiling a program and suddenly there is an error because you need a file that you do not have. The auto-apt program prompts you to install packages if they are needed, stopping the relevant process and continuing once the package is installed.

      # auto-apt run ./configureThen it will ask you to install the necessary packages and call apt-get automatically. If you’re running X, a graphical interface will replace the default text interface.

Maintenance commands

  • apt-get update

    Run this command after changing /etc/apt/sources.list or /etc/apt/preferences. For information about /etc/apt/preferences, see PinningHowto. Run this command periodically to ensure that the list of sources is up to date. This is the equivalent of “Reload” in Synaptic or “Fetch updates” in Adept.

  • apt-get upgrade This command updates all installed packages. This is the equivalent of “Mark all updates” in Synaptic.
  • apt-get dist-upgrade The same as above, except that you add the “smart upgrade” checkbox. It tells APT to use the “smart” conflict resolution system, and will try to update the most important packages at the expense of the less important ones if necessary.
  • apt-get check This command is a diagnostic tool. Updates package lists and checks for broken dependencies.
  • apt-get -f install

    This command does the same as Edit->Fix Broken Packages in Synaptic. Do this if you receive complaints about packages with “dependencies not satisfied”.

  • apt-get autoclean

    This command deletes .deb package files that are no longer installed on the system. Depending on your installation habits, deleting these files from /var/cache/apt/archives can reclaim a significant amount of disk space.

  • apt-get clean

    The same as above, except that it removes all packages from the packet cache. This may not be desirable if you have a slow internet connection, as it will cause you to re-download any packages you need to install a program.

    • The package cache is in /var/cache/apt/archives. The

      du -sh /var/cache/apt/archives command will tell you how much space the cached packages consume.

  • dpkg-reconfigure <package_name> Reconfigure the named package. With many packages, you’ll be asked for some configuration questions that you may not have known were there.
    • For example:

      dpkg-reconfigure fontconfig-config will present you with a “wizard” about font settings in Ubuntu.

  • echo “<package_name> hold” | dpkg -set-selections

    This command puts the desired packet on hold. TODO: Bug #42178: This is the same as Synaptic’s Package->Lock Version. */

  • echo “<package_name> install” | dpkg -set-selections This command deletes the “hold” or “locked package” state set by the previous command. The above note about using sudo applies to this command.

Removal commands

apt-get remove <package_name> This command deletes

  • an installed package, leaving the configuration files intact. apt-get
  • purge <package_name> This command completely deletes a package and associated configuration files. Configuration files that reside in ~ are typically not affected by this command.
    • + operator
      • If you want to remove package1 and install package2 in one step: apt-get remove <package1> <package2


  • apt-get autoremove This command removes packages that were installed by other packages and are no longer needed.
    • apt-get autoremove <package_name> This command removes an installed package and dependencies.
  • While there is no built-in way to delete all configuration information from deleted packages, you can delete all configuration data for each deleted package with the following command.

    dpkg -l | grep ‘^rc’ | awk ‘{print $2}’ | xargs dpkg -purge

  • apt-cache search commands <search_term>

    Each package has a name and description. This command lists packages whose name or description contains <search_term>.

  • dpkg -l *<search_term>*

    This will find packages whose names contain <search_term>. Similar to apt-cache search, but also shows if a package is installed on your system by marking it with ii (installed) and a (not installed).

  • apt-cache show <package_name>

    This command displays the package <package_name> description and other relevant information, including version, size, dependencies, and conflicts.

  • dpkg -print-avail <package_name> This command is similar to “apt-cache show”.
  • dpkg -L <package_name>

    This command will display the files in the <package_name> package.

  • dpkg -c foo.deb

    This command lists the files in the “foo.deb” package. Note that foo.deb is a path name. Use this command on .deb packages that you have downloaded manually.

  • dlocate <package_name>

    This command determines which installed package has <package_name>. Displays the files in installed packages that match <package_name>, with the name of the package they came from. Consider that this is a “reverse lookup” utility.

  • dpkg -S <filename_search_pattern>

    This command does the same thing as dlocate, but does not require the installation of any additional packages. It is slower than dlocate but has the advantage of being installed by default on all Debian and Ubuntu systems.

  • apt-file search <filename_search_pattern>

    This command acts as dlocate and dpkg -S, but searches all available packages. It answers the question, “What package does this file provide?”.

    • apt-file needs to be updated regularly as apt-get. Use the command

      : apt-file update apt-cache

  • pkgnames This command provides a list of all system packages
  • A general note about searching: If your search generates too long a list, you can filter the results by piping them through the grep command. Examples:

    apt-cache search <filename> | grep -w <filename> will

    • display only files containing <filename> as a full-word dpkg-L package

      | grep

    • /usr/bin

    • will list files located in the /usr/bin directory, useful if you’re looking for a particular executable.

For more information about apt-get, apt-cache, and dpkg, refer to their manual pages using the man command. These manuals will provide a broader scope of information, plus all the options you can use with each program.

  • Example:

    man apt-get


Typical usage example

I want

to feel the wind in my hair, I want the adrenaline of speed. So let’s install a racing game. But what racing games are available?

apt-cache search racing game

gives me many answers. I see a game called “torcs”. Let’s learn more about this game.

apt-cache show torcs

Hmmm… looks interesting. But isn’t this game already installed on my computer? And what is the available version? Which repository is it from (Universe or Main)?

apt-cache policy torcs

Ok, so now, let’s install it!

apt-get install

torcsWhat is the command I should type on the console to start this game? In this example, it’s simple (“torcs”), but it’s not always the case. One way to find the binary name is to look at what files the package has installed in “/usr/bin”. For games, the binary will be in “/usr/games”. For administrative programs, it is in “/usr/sbin”.

dpkg -L torcs | grep /usr/games/

The first part of the command displays all the files installed by the “torcs” package (try it). With the second part, we ask to show only lines containing “/usr/games/”.

Hmmm, that game is great. Maybe there are some extra clues?

apt-cache search torcs

But I’m running out of space. I will delete the apt cache!

apt-get clean

Oh no, my mother asked me to remove all games from this computer. But I want to keep the configuration files so I can just reinstall them later.

apt-get remove torcs

If I also want to delete configuration files:

apt-get purge torcs Configuring apt-get to use an http proxy

Here are three methods to use apt-get with an http proxy.

Temporary proxy session

This is a temporary method that you can use manually whenever you want to use apt-get through an http proxy. This method is useful if you only want to temporarily use an http proxy.

Enter this line in the terminal before using apt-get (replace your data with your proxy and proxyport address).

export http_proxy=http://yourproxyaddress:proxyport

If you normally use sudo to run apt-get, you’ll need to log in as root first for this to work, unless you also add some explicit environment settings to /etc/sudoers, for example,

Defaults env_keep = “http_proxy https_proxy ftp_proxy”

APT configuration

file method

This method uses the apt.conf file located in your /etc/apt/ directory. This method is useful if you only want apt-get (and not other applications) to use an http proxy permanently.

gksudo gedit /etc/apt/apt.conf

Add this line to your /etc/apt/apt.conf file (replace your data with yourproxyaddress and proxyport).

Acquire::http::P roxy “http://yourproxyaddress:proxyport”;

Save the apt.conf file.



This method adds two lines to the .bashrc file in the $HOME directory. This method is useful if you want apt-get and other applications, such as wget, to use an http proxy.

gedit ~/.bashrc

Add these lines to the end of your ~/.bashrc file (replace your data with

yourproxyaddress and proxyport) http_proxy=http://yourproxyaddress:proxyport export http_proxy

Save the file. Close your terminal window and then open another terminal window or the source of the ~/.bashrc file: source ~/.bashrc

Test your proxy with sudo apt-get update and any network tool you want. You can use firestarter or conky to view active connections.

If you make a mistake and edit the file again, you can

close the terminal and reopen it or

you can get ~/.bashrc as shown above. source ~/.bashrc How to log in

to a proxy user

If you need to log in to the proxy

server, this can be accomplished in most cases by using the following layout to specify the proxy address in http-proxy. (replace your data with username, password, youraddress and proxyport)


Useful additional packages

  • Deborphan Debfoster

Additional links

  • Repositories/CommandLine

  • PinningHowto

  • Synaptic

  • AutoDeb

  • Package Manager

  • Ubuntu Community Forums: Installations and Updates

  • What is apt-fast and should I use it?


  • https://help.ubuntu.com/community/PackageManagerTroubleshootingProcedure

CategoryPackageManagement CategoryCommandLine