Ubuntu Server 18.04 – Making use of Aptitude

Docker Compose Tutorial for Beginners

The aptitude command is a very useful, text-based utility for managing packages on your server. Some administrators use it as an alternative to apt, and it even has additional features that you won’t find anywhere else. To get started, you’ll need to install aptitude, if it isn’t already:

sudo apt install aptitude 

The most basic usage of aptitude allows you to perform functions you would normally be able to perform with apt. In the following table, I outline several example aptitude commands, as well as their apt equivalent (each one assumes sudo since you need root privileges to modify packages):

aptitude command

apt equivalent

aptitude install <packagename>

apt install <packagename>

aptitude remove <packagename>

apt remove <packagename>

aptitude search <search term>

apt-cache search <packagename>

aptitude update

apt update

aptitude upgrade

apt upgrade

aptitude dist-upgrade

apt dist-upgrade

 

For the most part, the commands I listed in the preceding table operate in much the same way as their apt equivalents. The output from an aptitude command will typically look very close to the apt version. There are some noteworthy differences, though.

First, compare the output from the search commands. Both commands will list package names, as well as a description for each package. The aptitude version places additional blank space in between the application name and description, which makes it look nicer. However, it also includes an additional column that the apt version doesn’t include, which represents the state of the package. This column is the first column you’ll see when you search for packages with aptitude, and will show i if the package is already installed, p if the package is not installed, and v if the package is virtual (a virtual package exists merely as a pointer to other packages). There are other values for this column; feel free to consult the man page for aptitude for more information.

Another useful trick with aptitude is the ability to fix a situation where the apt command lists a package as no longer being necessary, even though you would rather keep it around. If you recall, we went over this subject a few sections ago. Basically, if a package is installed as a dependency for another package (but the original package was removed), the package will be marked as automatically installed, which means it becomes a candidate for cleanup with the apt autoremove command. In some cases, you may wish to keep such a package around, and you’d rather the autoremove command not remove it from your system. To unmark a package as automatically installed, aptitude comes to our rescue with the following command:

sudo aptitude unmarkauto <packagename> 

After you unmark a package as automatically installed, it will no longer be a candidate for autoremove, and you can then use the apt autoremove command without fear that the package will be removed.

However, the aptitude command offers yet another nice feature in the form of a (somewhat) graphical interface you can interact with on the shell, if you enter the aptitude command (as root or with sudo) with no arguments or options:

sudo aptitude 
Aptitude in action

The aptitude command features an ncurses interface, which is essentially a Terminal equivalent of a graphical application. You are able to interact with aptitude in this mode by using your arrow keys to move around, Enter to confirm selections, and q to quit. Using aptitude‘s graphical utility, you are basically able to browse the available packages, which are split into several categories. For example, you can expand Not Installed Packages to narrow down the list to anything not currently installed, then you can narrow down the list further by expanding a category (you simply press Enter to expand a list). Once you’ve chosen a category, you’ll see a list of packages within that category that you can scroll through with your arrow keys. To manipulate packages, you’ll access the menu by pressing Ctrl + T on your keyboard, which will allow you to perform additional actions. Once in the menu, you can mark the package as a candidate for installation by using your arrow keys to navigate to Package, and then you can mark the package as needing to be installed by selecting Install. You can also mark a package as needing to be removed or purged (meaning the package and its configuration are both removed). In addition, you can mark a package as automatically installed (Mark Auto) or manually installed (Mark Manual). Once you’ve made your selections, the first menu item (Actions) has an option to Install/Remove packages, which can be used to finalize your new selections or removals. To exit from aptitude, access the menu and then select Quit.

There’s more that you can do with the graphical version of aptitude, so feel free to play around with it on a test server and read its man pages to learn more. In addition to being an awesome way to manage packages, it also has a built-in game of Minesweeper! Have a look around the application and see if you can find it.

As you can see, aptitude is a very useful utility, and some even prefer it to plain apt. Personally, I still use apt, though I always make sure aptitude is installed on my servers in case I need to benefit from its added functionality.

Comments are closed.