Using apt-get and aptitude

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Filtering and Search Patterns

Aptitude provides extensive options for searching for packages. Both the interactive interface and the command line include powerful filters and search patterning. The curses interface provides the search input with the Shift+/. In the CLI, the command is search followed by the search string.

In both cases, aptitude lets you input not only parts of the package name and regular expressions, but also special search patterns. These include ~i for all installed packages, ~M for all those automatically installed through dependencies, and ?description(<description>) in searching for package descriptions (Figure 2).

Figure 2: Aptitude helps effectively sift through the huge inventory of packages with search patterns and filters.

Most of the search patterns have both long and short forms. The long forms start with the question mark, and the short forms begin with the tilde character. A selection of search patterns is shown in Table 4; a full list is available online [11] and in the aptitude-doc-en package.

Table 4: Aptitude Search Patterns

?not(<pattern>) !<pattern> Packages that do not match the pattern
?and(<pattern1>, <pattern2>) <pattern1> <pattern2> Packages that match both patterns
?or(<pattern1>, <pattern2>) <pattern1> | <pattern2> Packages that match either or both patterns
?automatic ~M Automatically installed packages
?broken ~b Packages with a broken dependency
?config-files ~c Removed but not purged packages
?description(<Text>) ~d<Text> Packages whose description matches
?essential ~E Packages marked as essential in control files
?garbage ~g Packages not required by any manually installed package
?obsolete ~o nstalled packages that cannot be downloaded
?provides(<pattern>) ~P<pattern> Packages that provide a virtual package for searching patterns
?section(<section>) ~s<section> Packages in the given section
?upgradable ~U Installed packages that can be upgraded

These patterns also help filter the lists in the text interface and commands in the CLI. Use L to filter the text lists, where you get a search input box for entering a pattern, as in a search. The program displays only those software packages that match the pattern (in Figure 3, o[kc]ular). You can accurately find each package, even if the spelling isn't exactly right.

Figure 3: A search using a regular expression for the Okular PDF viewer.

Patterns also prove useful at the command line. The following command marks all packages that begin with the name lib as automatically installed:

# aptitude markauto '~n^lib'

You should normally only install software libraries that you actually use. Our example can have an undesirable side effect: It targets LibreOffice but picks up packages with header files (whose names typically are lib<name>-dev) and removes them, which was not what we wanted.

A more precise filtering is using the section name instead of the package name as the pattern. The following command marks all packages in the libs and oldlibs sections as "automatically installed":

# aptitude markauto '~slibs'

An explicit ~soldlibs option is not necessary because aptitude recognizes the pattern as part of a section name. Specific exceptions (e.g., libraries that end up in a system because of a dependency) can be dealt with through corrections to actions (see Table 3). After the previous command, aptitude would remove all libraries upon which no other packages depend – with the exception of the libtclcl1 package, marked as "not automatically installed," which remains installed.

aptitude markauto '~slibs' 'libtclcl1&m'

Another typical example is purging previously removed configuration and application data from already configured packages:

# aptitude purge '~c'

The same warning as for --purge-unused applies, however. When not used correctly, the action can lead to losing possibly required data. Thus, a setting for packages for the Debian MySQL server can determine whether the system should delete databases during a purge. In any case, a second look before executing the command is advised.

Aptitude proves to be much more complex and provides quite a few more options for managing packages. Of course, this also has its downside. The program uses considerably more time to start and end than apt-get. At startup, it reads its additional database to determine status and, when it closes, it saves it back to the hard disk. This happens even in cases when you would not think it necessary [13], making it a slower than apt-get.


If you want fine-grained yet efficient control of the packages you use, the mighty aptitude provides far and away more options than apt-get. However, it requires a bit more knowledge and a steeping learning curve, whereas apt-get gets a start right out of the gate. Apt-get might thus provide a better choice if you want to avoid "side effects" in prepared actions, such as accidentally deleting packages.

Once you have learned to appreciate aptitude's text mode interface with all its options for previewing and filtering, must always remember to call aptitude keep-all before each run, to remove all reservations.

If you're writing installation instructions for an Ubuntu package or article, you should make sure you always use apt-get in all your examples. Apt-get provides the basic functionalities and it's best to let the users decide whether to use apt-get or aptitude. As an author, you can't possibly anticipate what side effects could occur with aptitude.


The authors thank Lars Lingner for his encouragement and suggestions in preparing this article.


  1. "Apt and Aptitude, Part 1: Dynamic Duo," by Axel Beckert and Frank Hofmann, Ubuntu User, 18, pg. 44.
  2. Configuration in /etc/apt/apt.conf:
  3. Modular configuration in /etc/apt/apt.conf.d/:
  4. Manpage for run-parts:
  5. Aptitude configuration file reference:
  6. Commands for aptitude and apt-get:
  7. Managing packages behind a proxy:
  8. Apt from behind a proxy:
  9. Ubuntu forum:
  10. Stump Window Manager:
  11. Aptitude search pattern reference:
  12. Aptitude user's manual:
  13. Daniel Hartwig's response to Debian bug #693144:

The Author

Axel Beckert ( works as Linux system administrator at ETH Zurich, sits on the board of the Linux User Group Switzerland and is a member of the Debian project. He has assumed the role of mentor, guinea pig, and package sponsor since the restructuring of the aptitude team.

Frank Hofmann ( works in Berlin as a service provider for typesetting and printing. Since 2008, he's been coordinating the regional meetings of the Linux User Group for the Berlin-Brandenburg region.

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content