Package management in Linux: apt and dpkg

Updated November 1, 2026

apt installs, updates and removes packages from repositories, while dpkg handles a single .deb file.

Common cases

sudo apt update              # refresh the package list
sudo apt install nginx       # install a package
sudo apt remove nginx        # remove a package
apt search nginx             # find a package by name
dpkg -l                      # list installed packages
sudo dpkg -i ./pkg.deb       # install from a local .deb

Sample output

$ sudo apt install -y jq
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libjq1 libonig5
The following NEW packages will be installed:
  jq libjq1 libonig5
0 upgraded, 3 newly installed, 0 to remove and 11 not upgraded.
Need to get 371 kB of archives.
After this operation, 1236 kB of additional disk space will be used.
...

How it works: apt sits on top of dpkg

The low-level dpkg is what actually installs a package: it unpacks one .deb and records it in a database. But dpkg cannot find packages on the internet or pull in dependencies on its own. apt does that: it downloads the package and everything it needs from the repositories and calls dpkg to install them. So day to day you use apt, and dpkg -i is for when you already have a .deb file in hand. On Fedora and RHEL the same job is done by dnf and rpm.

Common mistakes

Without sudo, apt stops at the first step: E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied), then are you root?. The rights you lack are for the lock file and the package database in /var/lib/dpkg, not for the download. Reading needs no rights: dpkg -l, apt list --installed and apt search run as a normal user.

E: Unable to locate package jq almost never means the package does not exist. It means the package is not in your local list: right after a fresh install, or after you add a repository, that list is empty or stale, and sudo apt update refreshes it. Do not mix this up with apt upgrade: update downloads the list of versions, upgrade installs newer versions of the packages themselves.

apt remove deletes the program's files and keeps its settings. After apt remove nano the package list still holds rc nano 7.2-2ubuntu0.2 arm64 small, friendly text editor inspired by Pico: r for removed, c for config files still in place, and /etc/nanorc is untouched. Install the package again and your old config comes back with it. sudo apt purge nano takes that away too.

In the book

This topic is covered in full in the chapter Packages and software.

See also

which, type, whereis.