An improved front end for Apt

Apt on Steroids

© Photo by Lopez Robin on Unsplash

© Photo by Lopez Robin on Unsplash

Author(s):

The Nala front end for Debian's Apt package manager combines the reliability of the Apt tools with easier to read output and speedier downloads.

Debian's package management system for the command line relies on dpkg [1] in the background and the Advanced Package Tool (Apt) [2] with its default front end, apt. While apt usually does a reliable job, its command-line tools (based on the libapt-pkg and libapt-inst libraries), such as apt, apt-file, apt-policy, and the like, are not particularly clear-cut or attractive. In addition, the Apt front end is slow.

This, along with other shortcomings in the tools available in Debian, prompted longtime Debian developer, Michael Stapelberg, to announce his retirement in 2019 with some harsh criticism [3]. Stapelberg subsequently created the proof of concept distri distribution, with the goal of optimizing package management in general (Linux Magazine previously covered distri in July 2021 [4]).

Nala, which was inspired by Fedora's DNF package manager, steps up to eradicate these shortcomings, offering easier to read output and increased speed thanks to parallel downloading.

What Apt Does

As part of Apt on Debian, Ubuntu, and their derivatives, apt is the interactive command-line utility that takes care of package management. It performs tasks such as installing, uninstalling, or searching for packages and displaying information about them. While apt does not offer color-highlighted output (Figure 1), it does at least have a progress bar. You can interact with apt through subcommands such as update, upgrade, full-upgrade, install, remove, and purge. The packages installed via apt are based on the repositories entered in the source list below /etc/apt/sources.list.d/.

Figure 1: With apt, the output for updating the source list is a mess of information without any clear focus on important facts.

Since the beginning of the year, another Apt front end named Nala has been making the rounds. Unlike apt, Nala uses the python-apt [5] library. This library provides access to almost all the features supported by Apt's underpinnings, the libapt-pkg and libapt-inst libraries. It's only logical that front-end programs for Apt, such as Nala, can be written in Python.

Although still quite new, Nala can already be found in the repositories of distributions such as Debian Testing and Unstable, Kali Linux, MX Linux, Raspbian Testing, and Ubuntu 22.04 backports. For other Debian derivatives, you need to include the developer's repository as described in the wiki on GitLab [6]. Alternatively, you can download the tool as a DEB package and install it directly.

Currently, Nala version 0.11.1 can be used in the Bash, ZFS, and Fish shells. For Debian Stable, Ubuntu 21.04, and distributions based on their package set, you need to use the nala-legacy package, which provides the same functions and is only adapted to the older package set in terms of dependencies. You cannot use Nala with older distributions, such as Ubuntu 18.04 or Debian 10 (buster).

What Nala Offers

Because of the many changes, it is important to be able to intuitively understand the package manager's output during package installations or updates of the entire installation at the command line – especially if you use Debian Testing or Unstable, or other rolling release distributions based on DEB packages. This desire for clarity is one of the starting points for Nala: The output should be more accessible, detailed where necessary, and unobtrusive where possible. Nala achieves this goal by using more color highlighting and clearer output formatting (Figure 2).

Figure 2: With Nala, you can immediately see which repositories have been updated since the last update. In addition, the output also highlights ignored sources.

When called, Nala acts a little different from apt. The command

sudo nala update

has the same result as

sudo apt update

It updates the sources list in etc/apt/sources.list.d. On the other hand, if you type

sudo nala upgrade

Nala will run an

apt update && apt full-upgrade

as shown in Figure 3. This is because the developers designed Nala with rolling releases in mind. However, the command works just as well on stable distributions.

Figure 3: Nala highlights the new version of the packages to be upgraded in the right column when upgrading. The summary clearly shows the packages to be installed and upgraded, as well as the scope of the upgrade.

When updating, Nala highlights important aspects of the output in color, which shows at a glance which repositories offer new packages and to which version a package will be updated. In addition, the tool color highlights all of the repositories that it ignores due to an incorrect configuration or a missing key. While updating packages, Nala reliably shows you a progress bar with the remaining time, the completed workload as a percentage, and the number of packages already processed compared to the total update (Figure 4).

Figure 4: After successfully completing an upgrade, Nala will inform you about the progress and prompt you if a restart is needed.

One of Nala's less desirable quirks is to additionally integrate

sudo nala upgrade

with

sudo apt autoremove

which removes packages that are no longer needed (Figure 5). As experience shows, packages that are actually needed will still disappear from time to time. The recommended approach is to prevent this behavior by calling Nala with the --no-autoremove parameter.

Figure 5: If you do not want Nala to execute the autoremove command during an upgrade, you can prevent it in the configuration file.

Alternatively, you can prevent this behavior permanently in the /etc/nala/nala.conf file by setting the second entry to auto_remove = false. If you want Nala to clean up the package inventory, use the --autoremove parameter. In the configuration file, you will find some additional simplifying settings that Apt does not offer, which includes hooks that automatically perform scripted actions before or after installing a package. A video on Reddit explains this feature and shows an example [7].

If apt is indelibly embedded in your finger muscle memory, you can create an alias and keep using the familiar commands while Nala is working in the background.

What Slows Apt Down

Since 2002, the Debian developers have been resisting allowing parallel downloading from the same server on the grounds that it puts too much load on the servers while offering little gain [8]. Today, in view of HTTP/2 and soon HTTP/3, this argument needs to at least be verified. Other distributions have long since allowed parallel downloading from the same host. On Debian, you can install the apt-fast shell script wrapper from GitHub [9]; it drastically improves apt's download times by downloading packages in parallel, with multiple connections per host.

Nala makes apt-fast obsolete: Parallel downloading is already part of Nala's strategy. By default, Nala downloads three packages per unique mirror server in your source list. Also, Nala alternates downloads between available mirrors to boost speed further. If a server fails for any reason, Nala tries the next one until it has processed all defined servers.

And that's not all: You can run

sudo nala fetch

to tell Nala to test all available mirror servers for the performance at your location (Figure 6). In testing, Nala speed-checked 332 servers, resulting in a list of the 16 fastest German and European servers at our site. The first server in the list had a response time of 21ms, while the last clocked in at 28ms. You can enter the desired servers as a space-separated list of numbers and confirm by pressing the Enter key. Nala then writes the desired servers to a new source list named nala-sources-list and uses it from then on. It is a good idea to repeat this procedure every few months.

Figure 6: The nala fetch command checks all Debian mirrors and selects the fastest ones for your location.

Historical

Have you ever tried to undo an upgrade that went wrong in Debian? For individual packages, this can easily be done by specifying the desired version for the downgrade next to the package name, as in

sudo apt install foo=0.98.2

However, if you are updating a large number of packages, you then end up with constructs like the one shown in Listing 1.

Listing 1

Specifying a Downgrade

$ awk '$1 == "2022-08-25" && $3 == "upgrade" {print $4"="$5}' /var/log/dpkg.log

Nala offers you a history function borrowed from Fedora's DNF package manager. It not only shows you what happened during the update, but it can also roll back the results completely. Currently, the history function is still under development and only works for individual packages and their dependencies. The output from

sudo nala history

shows the most recent actions, whether this be a single package installation, a removed package, or a system upgrade with 300 packages.

Especially for system upgrades where a bug has crept in, the history function will be immensely helpful once it is fully implemented. There are good reasons for more and more distributions to use snapshots and atomic upgrades in the form of images. However, because these modern techniques are still a long way off in Debian, Nala's history function offers a passable alternative option that requires hardly any effort.

The line-by-line output of history starts on the left with an ID, which plays a crucial role for rolling back (Figure 7). This is followed by the apt command, with Nala still partly confusing update with upgrade as parameters. But because this is only about information, it does not have any real implications. Once you have found the action to undo, use the ID of the line in

sudo nala history undo <ID>
Figure 7: Nala's history function will support rolling back complete upgrades in the future, which is very helpful should something go wrong during an update.

After doing so, everything reverts to the way it was before. If you do change your mind,

sudo nala history redo <ID>

will reverse the process and reinstall the upgrade.

Conclusions

Nala adds some important features to Debian's package management: The output is attractively colorful and informative. Clutter is avoided, with the tool highlighting everything that is important. Parallel downloads speed up updates and upgrades, while the fetch function additionally lets you choose the fastest mirror servers. But the real highlight is Nala's history function, which will beam Debian to a position close to snapshot-supported distributions in the future. The developer intends to port Nala from Python to Rust in the near future to increase download speed. He will then look to integrate the extended history function.

I have been using Nala daily for six months without any serious complications. In rare cases, the upgrade hangs for some unknown reason, but continues to run normally after pressing the Enter key. Nala extends apt in a way that makes it especially interesting for users of Debian Testing, Unstable, and their offshoots. However, thanks to Nala, updates are also more fun on Ubuntu and other Debian derivatives.