Manage Debian Packages with aptitude
Learn to use aptitude interactively and from the command line to search, install, upgrade, remove, and clean Debian packages.
aptitude is a package-management frontend for APT (the Advanced Package Tool). It is used on Debian and Debian-derived distributions to retrieve, resolve, install, upgrade, and remove software packages.
aptitude has two operating modes:
- Interactive mode: a menu-driven text interface for browsing packages and queuing operations.
- Command-line mode: explicit actions such as
update,search,install,full-upgrade, andclean.
Its common package-management tasks are conceptually similar to apt-get and other APT clients. The commands are not interchangeable in every detail, but the same APT package data and dependency-resolution concepts apply.
This lesson assumes basic terminal use, familiarity with sudo, and a general understanding of software repositories. For related command-line fundamentals, see Show the Full Path of Shell Commands.
Package-management concepts
| Term | Meaning |
|---|---|
| Package | A versioned archive containing software, metadata, and installation information. |
| Repository | A configured source of package metadata and package files. |
| Package list | Locally stored metadata describing packages available from configured repositories. |
| Installed package | A package currently installed on the system. |
| Available package | A package described by the local package lists, whether or not it is installed. |
| Dependency | Another package required for a package to function or be installed. |
| Upgrade | Replacing an installed package with a newer version, when one is available. |
| Removal | Uninstalling a package. This is distinct from deleting downloaded package archives. |
| Package cache | Locally downloaded package archive files retained after packages are obtained or installed. |
Before installing or upgrading, refresh the package lists. A refresh downloads current repository metadata; it does not by itself install or upgrade software. Without a recent refresh, aptitude may not know about new package versions or may fail to find a package that is available in a configured repository.
In interactive mode, marking selects an operation for later execution. Marking a package for installation, removal, or upgrade does not immediately change the system. The queued operations are applied only after you review them and confirm the operation.
Starting the interactive aptitude interface
aptitude
Running aptitude without a subcommand opens its text-based interface. The display normally contains package categories, a package listing, status information, and a command or help area.
- Use the arrow keys to move through categories and package entries.
- Expand or collapse categories to browse their packages.
- Use the search command to locate a package by name or expression.
- Mark operations on selected packages, then review the pending-action summary.
- Use the apply action to download and execute the queued changes.
Administrative operations may require elevated privileges. If the interface cannot perform a system change because of permissions, start it with sudo aptitude, or follow the privilege prompt provided by the system.
Interactive aptitude keyboard shortcuts
| Key | Action | When to use it |
|---|---|---|
u | Refresh available package lists | Before searching for newly available packages or checking upgrades. |
/ | Search for a package | To find a package by name or search expression. |
+ | Mark a package for installation | After selecting a package to install. |
- | Mark a package for removal | After selecting an installed package to uninstall. |
U | Mark upgradable packages for upgrade | After refreshing package lists and checking available upgrades. |
g | Review and then apply queued package actions | After marking changes and before committing them. |
Keyboard shortcuts are case-sensitive. In particular, lowercase u refreshes package information, while uppercase U marks eligible installed packages for upgrade.
Install nmap interactively
nmap is a network-scanning utility and a useful example package.
- Open the interface with
aptitude, using elevated privileges if required. - Press lowercase
uto refresh package information. Wait for the update to finish. - Press
/, enternmap, and submit the search. - Select the intended
nmappackage in the results. - Press
+to mark it for installation. Aptitude may also mark dependencies needed bynmap. - Press
gto display the proposed actions. - Review package names, versions, downloads, and any removals or replacements. Confirm only when the plan is understood.
- Continue through the confirmation prompt to download and install the package.
The package is not installed when you press +; that only queues the operation. The actual installation begins during the g apply step.
Upgrade packages interactively
- Open aptitude and press lowercase
uto refresh repository package lists. - Press uppercase
Uto mark all eligible installed packages for upgrade. - Press
gto review the proposed upgrade plan. - Inspect the versions, dependencies, downloads, and any package additions, replacements, or removals.
- Confirm the plan to apply the upgrades.
Remove nmap interactively
- Open aptitude and locate the installed
nmappackage by browsing or pressing/and searching fornmap. - Select the installed package entry and press
-to mark it for removal. - Press
gto review the pending removal and any related dependency changes. - Confirm the operation to apply the removal.
Removing nmap uninstalls the package, but it does not necessarily delete downloaded package archives from the local cache. Cleaning cached archives is a separate operation.
Using aptitude from the command line
The general command form is:
aptitude ACTION [PACKAGE_NAME_OR_PATTERN]
Actions that change system packages generally require root privileges, commonly supplied through sudo.
Search for packages
aptitude search nmap
This searches available package metadata for a package name or search expression. If the results are too broad, use a more specific name or pattern.
Refresh package lists
sudo aptitude update
This downloads current metadata from configured APT repositories. It does not install updates.
Install a package
sudo aptitude install PACKAGE_NAME
sudo aptitude install nmap
Aptitude calculates dependencies and proposes the packages required to install the requested package. Review the proposal before confirming.
Perform a full upgrade
sudo aptitude full-upgrade
full-upgrade upgrades installed software while allowing dependency-related changes needed to complete the operation. Compared with a conservative upgrade, it may add, replace, or remove packages.
Clean downloaded package archives
sudo aptitude clean
clean deletes downloaded package archive files from the local package cache. It does not uninstall currently installed software. Cached archives can be useful for reinstalling without downloading again, so clean them when reclaiming disk space is more important than retaining those files.
Interactive actions versus command-line commands
| Goal | Interactive method | Command-line method |
|---|---|---|
| Refresh package metadata | Press u | sudo aptitude update |
| Search | Press /, then enter a name or pattern | aptitude search PACKAGE_NAME |
| Install | Select a package, press +, then press g to apply | sudo aptitude install PACKAGE_NAME |
| Upgrade | Press U, then press g to apply | sudo aptitude full-upgrade |
| Remove | Select an installed package, press -, then press g to apply | sudo aptitude remove PACKAGE_NAME |
| Clean package cache | Use the interface's package-cache cleanup action, if available | sudo aptitude clean |
Verify package operations
After installing a package, query its installed state:
aptitude search '^nmap$'
An installed package is normally shown with an installed-state marker in the search output. You can also ask aptitude to display package details:
aptitude show nmap
For a more direct Debian package database check, use:
dpkg-query -W -f='${Status}\n' nmap
A successful installed result contains install ok installed. After an upgrade, run the same package query or inspect the installed version with aptitude show PACKAGE_NAME. After removal, confirm that the package no longer appears as installed.
Troubleshooting
A package cannot be found
- Refresh the package lists with
sudo aptitude updateor interactiveu. - Check that the package name is spelled correctly; try a broader search expression.
- Check whether the repository containing the package is enabled in the system's configured APT software sources.
Marked changes do not happen immediately
Marking queues an operation; it does not commit it. Press g, inspect the action summary, and confirm the apply step.
Dependency conflicts are reported
Conflicts can result from incompatible requested versions, held packages, obsolete packages, or mixed repositories. Read the proposed solution carefully. Do not accept removals or replacements unless you understand their effect. Refresh the package lists and reassess the requested packages if the proposal is unexpected.
A command reports permission denied
Package installation, removal, upgrades, and cache cleanup modify system files. Run the command with sudo, such as sudo aptitude install nmap, or use an administrator account.
Disk space remains low
Downloaded package archives may still occupy space in the package cache. After checking that you do not need those archives for offline reuse, run:
sudo aptitude clean
This removes cached archive files without uninstalling software that is already installed.
Exam-relevant summary
aptitudeis an APT frontend for Debian and Debian-derived systems.- Running
aptitudeopens an interactive text interface; explicit actions use command-line mode. - Refresh package lists before searching, installing, or checking upgrades.
- Interactive marks are queued changes;
greviews and applies them. - Lowercase
uupdates package lists, while uppercaseUmarks upgrades. full-upgradecan change dependencies by adding, replacing, or removing packages.cleandeletes downloaded package archives; it does not remove installed software.