Get the highlights in your inbox every week.
Linux package management with apt | Opensource.com
Linux package management with apt
Learn how to install packages on Debian-based Linux distros with the apt command, then download our cheat sheet to keep the right command at your fingertips.
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—have
apt, 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
- Aptitude is an Ncurses-based full-screen command-line front end for
- There are
apt-cache, and other predecessors of
- Dpkg is the "behind the scenes" package manager
aptuses to do the heavy lifting.
aptand 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
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 as
apt is finding a software package of interest. Seth's
dnf article used the Cockpit server management application as an example, so I will, too:
$ apt search cockpit
Full Text Search... Done
389-ds/hirsute,hirsute 18.104.22.168-1 all
389 Directory Server suite - metapackage
cockpit/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
cockpit/hirsute). If you decide you want to install it, enter:
$ sudo apt install cockpit
apt will take care of installing Cockpit 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 deciding whether you really want to install this application.
To find out more about a package, use the
apt show command:
$ apt show cockpit
Maintainer: Ubuntu Developers <firstname.lastname@example.org>
Original-Maintainer: Utopia Maintenance Team <email@example.com>
Installed-Size: 88.1 kB
Depends: cockpit-bridge (>= 238-1), cockpit-ws (>= 238-1), cockpit-system (>= 238-1)
Recommends: cockpit-storaged (>= 238-1), cockpit-networkmanager (>= 238-1), cockpit-packagekit (>= 238-1)
Suggests: cockpit-doc (>= 238-1), cockpit-pcp (>= 238-1), cockpit-machines (>= 238-1), xdg-utils
Download-Size: 21.3 kB
APT-Sources: http://ca.archive.ubuntu.com/ubuntu hirsute/universe amd64 Packages
Description: Web Console for Linux servers
The Cockpit Web Console enables users to administer GNU/Linux servers using a
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-qt5
Full Text Search... Done
However, a related command,
apt-file will explore inside packages:
$ apt-file search qmake-qt5
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
What files are included in a package?
apt-file command also tells which files are included in a given package. For example:
$ apt-file list cockpit
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
$ 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
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.
apt cheat sheet to get used to the command and try some new tricks with it. Once you do, you might find it hard to use anything else.