Linux aptitude Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the aptitude package manager on an Ubuntu 22.04 Docker container. We will learn how to install and update aptitude, perform package searches and information lookups, and manage package installations, upgrades, and removals using aptitude commands. The lab covers essential package management tasks, providing practical examples to enhance your Linux system administration skills.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/TextProcessingGroup -.-> linux/grep("`Pattern Searching`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/apt -.-> lab-422551{{"`Linux aptitude Command with Practical Examples`"}} linux/grep -.-> lab-422551{{"`Linux aptitude Command with Practical Examples`"}} linux/sudo -.-> lab-422551{{"`Linux aptitude Command with Practical Examples`"}} end

Install and Update aptitude Package Manager

In this step, we will install and update the aptitude package manager on our Ubuntu 22.04 Docker container.

First, let's update the package index to ensure we have the latest package information:

sudo apt-get update

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done

Next, let's install the aptitude package manager:

sudo apt-get install -y aptitude

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  aptitude-common libboost-iostreams1.74.0 libboost-system1.74.0 libcwidget3v5 libept1.5.0 libxapian30
Suggested packages:
  aptitude-doc-en aptitude-doc
The following NEW packages will be installed:
  aptitude aptitude-common libboost-iostreams1.74.0 libboost-system1.74.0 libcwidget3v5 libept1.5.0 libxapian30
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,450 kB of archives.
After this operation, 5,580 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libboost-iostreams1.74.0 amd64 1.74.0-8ubuntu3 [139 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libboost-system1.74.0 amd64 1.74.0-8ubuntu3 [94.7 kB]
...
Fetched 1,450 kB in 1s (1,450 kB/s)
Selecting previously unselected package aptitude-common.
(Reading database ... 18284 files and directories currently installed.)
Preparing to unpack .../aptitude-common_0.8.12-1ubuntu1_all.deb ...
Unpacking aptitude-common (0.8.12-1ubuntu1) ...
Selecting previously unselected package aptitude.
Preparing to unpack .../aptitude_0.8.12-1ubuntu1_amd64.deb ...
Unpacking aptitude (0.8.12-1ubuntu1) ...
Setting up libboost-iostreams1.74.0:amd64 (1.74.0-8ubuntu3) ...
Setting up libboost-system1.74.0:amd64 (1.74.0-8ubuntu3) ...
Setting up libcwidget3v5:amd64 (0.5.17-7build1) ...
Setting up libept1.5.0:amd64 (1.1+nmu3ubuntu2) ...
Setting up libxapian30:amd64 (1.4.18-3ubuntu1) ...
Setting up aptitude-common (0.8.12-1ubuntu1) ...
Setting up aptitude (0.8.12-1ubuntu1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...

Now, let's verify that aptitude is installed and up-to-date:

In this step, we will learn how to use the aptitude package manager to search for packages and retrieve information about them.

First, let's search for a package using the aptitude search command. For example, let's search for the "nginx" package:

sudo aptitude search nginx

Example output:

i   nginx                                                        - high performance web server
p   nginx-core                                                   - nginx web server (core version)
p   nginx-doc                                                    - documentation for nginx
p   nginx-extras                                                 - nginx web server (extended version)
p   nginx-full                                                   - nginx web server (standard version)
p   nginx-light                                                  - nginx web server (basic version)

The output shows that there are several nginx-related packages available. The "i" prefix indicates that the "nginx" package is currently installed.

Next, let's get detailed information about the "nginx" package using the aptitude show command:

sudo aptitude show nginx

Example output:

Package: nginx
State: installed
Automatically installed: no
Version: 1.18.0-0ubuntu1.2
Priority: optional
Section: web
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Uncompressed Size: 1,518 k
Depends: nginx-core (= 1.18.0-0ubuntu1.2), lsb-base (>= 3.0-10)
Suggests: nginx-doc, www-browser
Description: high performance web server
 Nginx is a high performance web server and reverse proxy server. It is
 known for its high performance, stability, rich feature set, simple
 configuration, and low resource consumption.

This provides detailed information about the "nginx" package, including its version, dependencies, and a description of the package.

Install, Upgrade, and Remove Packages using aptitude

In this step, we will learn how to use aptitude to install, upgrade, and remove packages.

First, let's install a new package using the aptitude install command. We'll install the "tree" package, which is a command-line utility that displays the directory structure in a tree-like format:

sudo aptitude install tree

Example output:

The following NEW packages will be installed:
  tree
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 44.2 kB of archives. After this operation, 123 kB of additional disk space will be used.
Do you want to continue? [Y/n/?] y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 tree amd64 1.8.0-1build1 [44.2 kB]
Fetched 44.2 kB in 0s (89.3 kB/s)
Selecting previously unselected package tree.
(Reading database ... 18291 files and directories currently installed.)
Preparing to unpack .../tree_1.8.0-1build1_amd64.deb ...
Unpacking tree (1.8.0-1build1) ...
Setting up tree (1.8.0-1build1) ...
Processing triggers for man-db (2.10.2-1) ...

Next, let's upgrade a package using the aptitude safe-upgrade command. We'll upgrade the "vim" package to the latest version:

sudo aptitude safe-upgrade vim

Example output:

The following packages will be upgraded:
  vim vim-common vim-runtime
3 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,483 kB of archives. After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n/?] y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim-common amd64 2:8.2.3995-1ubuntu2.1 [2,138 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim-runtime all 2:8.2.3995-1ubuntu2.1 [4,178 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim amd64 2:8.2.3995-1ubuntu2.1 [167 kB]
Fetched 6,483 kB in 1s (6,483 kB/s)
(Reading database ... 18292 files and directories currently installed.)
Preparing to unpack .../vim-common_2%3a8.2.3995-1ubuntu2.1_amd64.deb ...
Unpacking vim-common (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Preparing to unpack .../vim-runtime_2%3a8.2.3995-1ubuntu2.1_all.deb ...
Unpacking vim-runtime (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Preparing to unpack .../vim_2%3a8.2.3995-1ubuntu2.1_amd64.deb ...
Unpacking vim (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Setting up vim-common (2:8.2.3995-1ubuntu2.1) ...
Setting up vim-runtime (2:8.2.3995-1ubuntu2.1) ...
Setting up vim (2:8.2.3995-1ubuntu2.1) ...
Processing triggers for man-db (2.10.2-1) ...

Finally, let's remove the "tree" package using the aptitude remove command:

sudo aptitude remove tree

Example output:

The following packages will be REMOVED:
  tree
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B of archives. After this operation, 123 kB disk space will be freed.
Do you want to continue? [Y/n/?] y
(Reading database ... 18292 files and directories currently installed.)
Removing tree (1.8.0-1build1) ...
Processing triggers for man-db (2.10.2-1) ...

Summary

In this lab, we learned how to install and update the aptitude package manager on our Ubuntu 22.04 Docker container. We started by updating the package index to ensure we have the latest package information, and then installed the aptitude package manager. We also explored how to perform package searches and information lookups, as well as how to install, upgrade, and remove packages using aptitude.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like