Aptitude command examples to manage packages – Ubuntu / Linux Mint

By | April 1, 2023


Aptitude is the another command that can be used to manage packages from the commandline just like dpkg and apt-get.

Aptitude is considered better and superior to apt-get for a number of reasons.

One benefit of aptitude is that when removing a certain package, aptitude will remove all dependencies of that package as well, so that they are not left behind as orphan packages. Apt-get and synaptic cannot do that and lead to unused/orphan packages.

In this quick tutorial we shall take a look some of the basic examples of how to use the aptitude command to manage packages on Ubuntu and ubuntu based distros like linux mint, pop os, kubuntu, xubuntu, elementary os etc.

1. Install a package

Same as apt-get, just use the install command with aptitude to install any package

$ sudo  aptitude install apache2

You can use the tab key press after the partially typing the package name and it will autocomplete itself or show list of matching package names to select from.

2. Remove / Uninstall packages

Again, same as apt-get, use the remove option.

$ sudo aptitude remove apache2

3. Search the packages

One of the most useful and frequent task is to search for packages and install any necessary ones. Searching from the command line is very handy on a remote server where you don't have a gui and as well on a local system when you dont want to launch the synaptic package manager.

The following command shall search all packages that have the word nginx in their package name.

$ aptitude search nginx

The following will search packages which have either php or admin in their names.

$ aptitude search php admin

To search for all search terms together wrap in single quotes. The following will search for all packages that have both php and admin in their names

$ aptitude search 'php admin'
p   mlmmj-php-web-admin                   - administrative web interface for mlmmj, written 
p   phpldapadmin                          - web based interface for administering LDAP serve
i   phpmyadmin                            - MySQL web administration tool                   
i   phppgadmin                            - web-based administration tool for PostgreSQL

To search both the package name and description use the d modifier.

aptitude search nginx ~dnginx
aptitude search 'firmware ~dwireless'

The search function supports regex as well

aptitude search ^nginx$

So construct any kind of regular expression you need and search right away.

4. Search installed packages

Lets say we want to search only the installed packages with the name nginx in it. The aptitude command can be used with the i switch as shown below

aptitude search ~inginx
aptitude search '~inginx'
$  aptitude search '~iapache'
i   apache2                                         - Apache HTTP Server metapackage                            
i A apache2-mpm-prefork                             - Apache HTTP Server - traditional non-threaded model       
i   apache2-suexec                                  - Standard suexec program for Apache 2 mod_suexec           

Alternatively you can also use grep instead of the i switch.

$ aptitude search nginx | grep ^i
i   nginx                           - small, powerful, scalable web/proxy server
i A nginx-common                    - small, powerful, scalable web/proxy server
i A nginx-full                      - nginx web/proxy server (standard version)

Quick and easy.

5. Reinstall package

To reinstall a package using aptitude use the reinstall command

aptitude reinstall <package>


The aptitude command makes it really quick and easy to find and install packages from the command also view the details about individual packages like version number etc.

There are other commands for managing packages like apt, apt-get, apt-cache, dpkg, gdebi etc on ubuntu. You should take a look at those commands as well.

Have any questions ? Let us know in the comments below.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *