Cyberithub

21+ aptitude Command Examples for Package Management in Linux

Advertisements

In this article, I will take you through 21+ aptitude command examples for package management in Linux. aptitude is an open source high-level text-based interface to the Debian/Ubuntu based Linux systems. It allows user to view the list of packages and to perform package management tasks such as installing, upgrading, and removing packages. Actions may be performed from a visual interface or from the command-line. We will see some of the real world examples of aptitude command in below section. More about aptitude.

21+ aptitude Command Examples for Package Management in Linux

aptitude command examples for Package Management in Linux

Also Read: 21+ Practical dpkg command examples for Linux Beginners

Example 1: How to Check aptitude command version

If you want to check aptitude command version then you need to use aptitude --version command as shown below. As you can see current aptitude version is 0.8.13.

root@debian:~# aptitude --version
aptitude 0.8.13
Compiler: g++ 10.2.1 20210110
Compiled against:
apt version 6.0.0
NCurses version 6.2
libsigc++ version: 2.10.4
Gtk+ support disabled.
Qt support disabled.

Current library versions:
NCurses version: ncurses 6.2.20201114
cwidget version: 0.5.18
Apt version: 6.0.0

 

Example 2: How to Install a Package using aptitude command

If you want to install a package then you need to use aptitude install <package_name> -y syntax. In this example, we are installing wget command by using aptitude install wget -y command as shown below.

root@debian:~# aptitude install wget -y
The following NEW packages will be installed:
wget
0 packages upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/964 kB of archives. After unpacking 3,560 kB will be used.
(Reading database ... 135755 files and directories currently installed.)
Preparing to unpack .../wget_1.21-1+b1_amd64.deb ...
Unpacking wget (1.21-1+b1) ...
Setting up wget (1.21-1+b1) ...
Processing triggers for man-db (2.9.4-2) ...

 

Example 3: How to remove a Package using aptitude command

If you want to remove a package then you need to use aptitude remove <package_name> -y syntax. In this example we are removing wget command by using aptitude remove wget -y command as shown below.

root@debian:~# aptitude remove wget -y
The following packages will be REMOVED:
wget
0 packages upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Need to get 0 B of archives. After unpacking 3,560 kB will be freed.
(Reading database ... 135844 files and directories currently installed.)
Removing wget (1.21-1+b1) ...
Processing triggers for man-db (2.9.4-2) ...

 

Example 4: How to Completely remove a Package using aptitude command

If you want to remove a package and all its configuration then you need to use aptitude purge <package_name> -y syntax. In this example, we are removing wget package by using aptitude purge wget -y command as shown below.

root@debian:~# aptitude purge wget -y
The following packages will be REMOVED:
wget{p}
0 packages upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Need to get 0 B of archives. After unpacking 3,560 kB will be freed.
(Reading database ... 135844 files and directories currently installed.)
Removing wget (1.21-1+b1) ...
Processing triggers for man-db (2.9.4-2) ...
(Reading database ... 135755 files and directories currently installed.)
Purging configuration files for wget (1.21-1+b1) ...

 

Example 5: How to Check complete detail about a Package

If you want to check complete information about a package then you need to use aptitude show <package_name> syntax. In this example, we are checking complete information about wget package using aptitude show wget command as shown below.

root@debian:~# aptitude show wget
Package: wget
Version: 1.21-1+b1
State: not installed (configuration files remain)
Multi-Arch: foreign
Priority: standard
Section: web
Maintainer: Noël Köthe <noel@debian.org>
Architecture: amd64
Uncompressed Size: 3,560 k
Depends: libc6 (>= 2.28), libgnutls30 (>= 3.7.0), libidn2-0 (>= 0.6), libnettle8, libpcre2-8-0 (>= 10.22), libpsl5 (>= 0.16.0), libuuid1 (>= 2.16), zlib1g
(>= 1:1.1.4)
Recommends: ca-certificates
Conflicts: wget-ssl

 

Example 6: How to hold a Package from Update using aptitude command

If you want to hold a package from update then you need to use aptitude hold <package_name> syntax. In this example, we are holding wget package from update by using aptitude hold wget command as shown below.

root@debian:~# aptitude hold wget

 

Example 7: How to Remove a Package from Hold

If you want to remove a package from hold then you need to use aptitude unhold <package_name> syntax. In this example, we are removing the hold from wget package by using aptitude unhold wget command as shown below.

root@debian:~# aptitude unhold wget

 

Example 8: How to Safely upgrade all the Packages in the System

If you want to safely upgrade all the packages in your System without any new package installation then you need to use aptitude safe-upgrade --no-new-installs command as shown below.

root@debian:~# aptitude safe-upgrade --no-new-installs
The following packages will be upgraded:
apache2-bin firefox-esr tzdata
3 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/57.1 MB of archives. After unpacking 84.0 kB will be used.
Do you want to continue? [Y/n/?] Y
Reading changelogs... Done
Preconfiguring packages ...
(Reading database ... 135755 files and directories currently installed.)
Preparing to unpack .../tzdata_2021a-1+deb11u1_all.deb ...
Unpacking tzdata (2021a-1+deb11u1) over (2021a-1) ...
Preparing to unpack .../apache2-bin_2.4.51-1~deb11u1_amd64.deb ...
Unpacking apache2-bin (2.4.51-1~deb11u1) over (2.4.48-3.1+deb11u1) ...

 

Example 9: How to Update all the Packages using aptitude command

If you want to update all the packages in your System then you need to use aptitude update command. This will download all the latest updates from configured Debian repo.

root@debian:~# aptitude update
Hit http://deb.debian.org/debian bullseye InRelease
Hit http://security.debian.org/debian-security bullseye-security InRelease
Get: 1 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Fetched 39.4 kB in 1s (33.0 kB/s)

 

Example 10: How to Cancel all the Scheduled actions on all the Packages

If you want to cancel all the scheduled actions on all the packages then you need to use aptitude keep-all command as shown below. Any packages whose sticky state indicates an installation, removal, or upgrade will have this sticky state cleared.

root@debian:~# aptitude keep-all

 

Example 11: How to Search a Package using aptitude command

If you want to search a package using some search pattern then you can do that with aptitude search command. In this example we are searching only wget package using ^wget$ search pattern.

root@debian:~# aptitude search ^wget$
i wget - retrieves files from the web

 

Example 12: How to only Download a .deb Package

If you want to only download a package and not really install it then you need to use aptitude download <package_name> syntax. This will download .deb package in local directory. In this example we are downloading wget package by using aptitude download wget command as shown below.

root@debian:~# aptitude download wget
Executing 'apt download wget'

You can verify the locally downloaded wget package by using ls -lrt wget* command as shown below.

root@debian:~# ls -ltr wget*
-rw-r--r-- 1 cyberithub cyberithub 964076 Sep 28 08:24 wget_1.21-1+b1_amd64.deb

 

Example 13: How to Forget all Internal information about packages that are 'new'

If you want to forget all internal information about all the packages that are 'new' then you need to use aptitude forget-new command as shown below.

root@debian:~# aptitude forget-new

 

Example 14: How to Remove all previously downloaded Packages from Cache

If you want to remove all previously downloaded .deb files from the package cache directory which is usually /var/cache/apt/archives then you need to use aptitude clean command as shown below.

root@debian:~# aptitude clean

 

Example 15: How to Remove any cached packages which can no longer be downloaded

If you want to remove any cached packages which can no longer be downloaded then you need to use aptitude autoclean command as shown below.

root@debian:~# aptitude autoclean
Freed 0 B of disk space

 

Example 16: How to Check available versions of a Package

If you want to check all the available versions of a package then you need to use aptitude versions <package_name> syntax. In this example we are checking all the available versions of wget package using aptitude versions wget command as you can see below.

root@debian:~# aptitude versions wget
i 1.21-1+b1 stable 500

 

Example 17: How to Check why a package should be installed

If you want to search for packages that require or conflict with the given package then you need to use why action. In this example we are searching for all the packages that require or conflict with the wget package.

root@debian:~# aptitude why wget
i pciutils Suggests wget | curl | lynx-cur

 

Example 18: How to Check why a package should not be installed

If you want to find a dependency chain leading to a conflict with the target package then you need to use why-not action with aptitude command. In this example, we are checking dependency chain which can lead to a conflict with wget package using aptitude why-not wget command as shown below. As you can see below, wget has no dependencies.

root@debian:~# aptitude why-not wget
Manually installed, current version 1.21-1+b1, priority standard
No dependencies require to remove wget

 

Example 19: How to forbid a Package from being upgraded to a particular version

If you want to forbid a package from being upgraded to a specific version then you need to use forbid-version action. In this example, we are forbidding vim package from being upgraded to 1.2.3.broken-4 version using aptitude forbid-version vim=1.2.3.broken-4 command as shown below.

root@debian:~# aptitude forbid-version vim=1.2.3.broken-4

 

Example 20: How to Get the Source of a Package using aptitude command

If you want to get the source of a package using aptitude command then you need to use aptitude source <package_name> syntax. In this example, we are downloading source of wget package in local directory using aptitude source wget command as shown below.

root@debian:~# aptitude source wget
Executing 'apt source wget'

Reading package lists... Done
Skipping already downloaded file 'wget_1.21-1.dsc'
Skipping already downloaded file 'wget_1.21.orig.tar.gz'
Skipping already downloaded file 'wget_1.21.orig.tar.gz.asc'
Skipping already downloaded file 'wget_1.21-1.debian.tar.xz'
Need to get 0 B of source archives.
dpkg-source: info: extracting wget in wget-1.21
dpkg-source: info: unpacking wget_1.21.orig.tar.gz
dpkg-source: info: unpacking wget_1.21-1.debian.tar.xz
dpkg-source: info: using patch list from debian/patches/series
dpkg-source: info: applying wget-doc-remove-usr-local-in-sample.wgetrc
dpkg-source: info: applying wget-doc-remove-usr-local-in-wget.texi
dpkg-source: info: applying wget-passive_ftp-default

You can list all the source files by using ls -lrd wget* command as shown below.

root@debian:~# ls -lrd wget*
-rw-r--r-- 1 root root 854 Jan 2 2021 wget_1.21.orig.tar.gz.asc
-rw-r--r-- 1 root root 4866788 Jan 2 2021 wget_1.21.orig.tar.gz
-rw-r--r-- 1 root root 2147 Jan 2 2021 wget_1.21-1.dsc
-rw-r--r-- 1 root root 60528 Jan 2 2021 wget_1.21-1.debian.tar.xz
drwxr-xr-x 16 root root 4096 Oct 12 06:56 wget-1.21

 

Example 21: How to Check all the options available with aptitude command

If you want to check all the options available with aptitude command then you need to use aptitude --help command as shown below.

root@debian:~# aptitude --help
aptitude 0.8.13
Usage: aptitude [-S fname] [-u|-i]
aptitude [options] <action> ...

Actions (if none is specified, aptitude will enter interactive mode):

install Install/upgrade packages.
remove Remove packages.
purge Remove packages and their configuration files.
hold Place packages on hold.
unhold Cancel a hold command for a package.
markauto Mark packages as having been automatically installed.
unmarkauto Mark packages as having been manually installed.
forbid-version Forbid aptitude from upgrading to a specific package version.
update Download lists of new/upgradable packages.
safe-upgrade Perform a safe upgrade.
full-upgrade Perform an upgrade, possibly installing and removing packages.
build-dep Install the build-dependencies of packages.

 

Example 22: How to Check Man Page of aptitude command

If you want to check the man page of aptitude command then you need to use man aptitude command as shown below.

root@debian:~# man aptitude
APTITUDE(8) Command-line reference APTITUDE(8)

NAME
aptitude - high-level interface to the package manager

SYNOPSIS
aptitude [<options>...] {autoclean | clean | forget-new | keep-all | update}

aptitude [<options>...] {full-upgrade | safe-upgrade} [<packages>...]

aptitude [<options>...] {build-dep | build-depends | changelog | download | forbid-version | hold | install | markauto | purge | reinstall |
remove | show | showsrc | source | unhold | unmarkauto | versions} <packages>...

aptitude extract-cache-subset <output-directory> <packages>...

aptitude [<options>...] search <patterns>...

Leave a Comment