Linux package management with apt (2024)

On Linux, package managers help you handle updates, uninstalls, troubleshooting, and more for the software on your computer. Seth Kenlon wrote about dnf, the command-line package management tool for installing software in RHEL, CentOS, Fedora, Mageia, OpenMandriva, and other Linux distros.

Debian and Debian-based distros such as MX Linux, Deepin, Ubuntu—and distros based on Ubuntu, such as Linux Mint and Pop!_OS—haveapt, a "similar but different" tool. In this article, I'll follow Seth's examples—but with apt—to show you how to use it.

Before I start, I want to mention four apt-related tools for installing software:

  • Synaptic is a GTK+ based graphical user interface (GUI) front end for apt.
  • Aptitude is an Ncurses-based full-screen command-line front end for apt.
  • There are apt-get, apt-cache, and other predecessors of apt.
  • Dpkg is the "behind the scenes" package manager apt uses to do the heavy lifting.

There are other packaging systems, such as Flatpak and Snap, that you might run into on Debian and Debian-based systems, but I'm not going to discuss them here. There are also application "stores," such as GNOME Software, that overlap with apt and other packaging technologies; again, I'm not going to discuss them here. Finally, there are other Linux distros such as Arch and Gentoo that use neither dnf nor apt, and I'm not going to discuss those here either!

With all the things I'm not going to discuss here, you may be wondering what tiny subset of software apt handles. Well, on my Ubuntu 20.04, apt gives me access to 69,371 packages, from the 0ad real-time strategy game of ancient warfare to the zzuf transparent application fuzzer. Not bad at all.

Finding software with apt

The first step in using a package manager such asapt is finding a software package of interest. Seth's dnf article used the co*ckpit server management application as an example, so I will, too:

$ apt search co*ckpitSorting... DoneFull Text Search... Done389-ds/hirsute,hirsute 1.4.4.11-1 all 389 Directory Server suite - metapackageco*ckpit/hirsute,hirsute 238-1 all Web Console for Linux servers...$

The second package above is the one you're after (it's the line beginning with co*ckpit/hirsute). If you decide you want to install it, enter:

$ sudo apt install co*ckpit

apt will take care of installing co*ckpit and all the bits and pieces, or dependencies, needed to make it work. Sometimes that's all that's needed; sometimes it's not. It's possible that having a bit more information could be useful in decidingwhether you really want to install this application.

To find out more about a package, use the apt show command:

$ apt show co*ckpitPackage: co*ckpitVersion: 238-1Priority: optionalSection: universe/adminOrigin: UbuntuMaintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>Original-Maintainer: Utopia Maintenance Team <pkg-utopia-maintainers@lists.alioth.debian.org>Bugs: https://bugs.launchpad.net/ubuntu/+filebugInstalled-Size: 88.1 kBDepends: co*ckpit-bridge (>= 238-1), co*ckpit-ws (>= 238-1), co*ckpit-system (>= 238-1)Recommends: co*ckpit-storaged (>= 238-1), co*ckpit-networkmanager (>= 238-1), co*ckpit-packagekit (>= 238-1)Suggests: co*ckpit-doc (>= 238-1), co*ckpit-pcp (>= 238-1), co*ckpit-machines (>= 238-1), xdg-utilsHomepage: https://co*ckpit-project.org/Download-Size: 21.3 kBAPT-Sources: http://ca.archive.ubuntu.com/ubuntu hirsute/universe amd64 PackagesDescription: Web Console for Linux servers The co*ckpit Web Console enables users to administer GNU/Linux servers using a web browser. . It offers network configuration, log inspection, diagnostic reports, SELinux troubleshooting, interactive command-line sessions, and more.$

In particular, notice the Description field, which tells you more about the application. The Depends field says what else must be installed, and Recommends shows what other—if any—cooperating components are suggested alongside it. The Homepage field offers a URL in case you need more info.

What package provides a file?

Sometimes you don't know the package name, but you know a file that must be in a package. Seth offers as an example the qmake-qt5 utility. Using apt search doesn't find it:

$ apt search qmake-qt5Sorting... DoneFull Text Search... Done$

However, a related command, apt-file will explore inside packages:

$ apt-file search qmake-qt5qt5-qmake-bin: /usr/share/man/man1/qmake-qt5.1.gz$

This turns up a man page for qmake-qt5 that is part of a package called qt5-qmake-bin. Note that this package name reverses the qmake and qt5 parts.

What files are included in a package?

That handy apt-file command also tells which files are included in a given package. For example:

$ apt-file list co*ckpitco*ckpit: /usr/share/doc/co*ckpit/TODO.Debianco*ckpit: /usr/share/doc/co*ckpit/changelog.Debian.gzco*ckpit: /usr/share/doc/co*ckpit/copyrightco*ckpit: /usr/share/man/man1/co*ckpit.1.gzco*ckpit: /usr/share/metainfo/co*ckpit.appdata.xmlco*ckpit: /usr/share/pixmaps/co*ckpit.png$

Note that this is distinct from the info provided by the apt show command, which lists the package's dependencies (other packages that must be installed).

Removing an application

You can also remove packages with apt. For example, to remove the apt-file application:

$ sudo apt purge apt-file

Note that a superuser must run apt to install or remove applications.

Removing a package doesn't automatically remove all the dependencies that apt installs along the way. However, it's easy to carry out that little bit of tidying:

$ sudo apt autoremove

Getting to know apt

As Seth wrote, "the more you know about how your package manager works, the easier it is for you to install and query applications when necessary."

Even if you're not a regular apt user, knowing it can be useful when you need to work at the command line while installing or removing packages (for example, on a remote server or when following a how-to published by some helpful soul). You may also need to know a bit about Dkpg (mentioned above); for example, some software creators provide a bare .pkg file.

I find the Synaptic package manager to be a really useful tool on my desktop, but I also use apt on a handful of servers that I maintain for various purposes.

Download our apt cheat sheetto get used to the command and try some new tricks with it. Once you do, you might find it hard to use anything else.

Linux package management with apt (1)This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Linux package management with apt (2024)

References

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5828

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.