Linux Package Management

By Vishvesh Patel · DevOps EngineerUpdated September 16, 2026

Install software across distributions, apt vs apt-get, remove vs purge, fixing dpkg lock errors, dnf and rpm, and when snap is worth it.

Why Package Management Matters

Package managers give Linux a reliable way to install, update, and remove software. Instead of downloading random installers, you use repositories that track dependencies and supported versions.

For DevOps teams, that predictability matters. It helps with server provisioning, patching, image builds, and keeping systems consistent across environments.

APT on Ubuntu and Debian

On Ubuntu and Debian based systems, apt is the standard package tool.

Refreshing package metadata

sudo apt update

This updates the local package index so the system knows what versions are available.

Installing packages

sudo apt install nginx
sudo apt install git curl

APT automatically resolves dependencies, which is one reason package management is easier than manual installs.

Removing packages and cleanup

sudo apt remove nginx
sudo apt autoremove

apt remove uninstalls the chosen package. apt autoremove cleans up dependency packages that are no longer needed.

Listing package information

apt list --installed
apt list --upgradable
apt list nginx

These commands help you check what is installed, what can be upgraded, and whether a package exists.

Tip: A safe APT habit is apt update first, then inspect or install. Old package metadata often causes confusion.

DNF and YUM on RHEL, CentOS, and Fedora

Red Hat style distributions commonly use dnf. Older guides may say yum, but the workflow is very similar.

Installing and updating

sudo dnf install nginx
sudo dnf install git curl
sudo dnf update

Removing and listing

sudo dnf remove nginx
dnf list installed
dnf list available
dnf list nginx

The pattern is the same as APT: install trusted packages, update carefully, and remove software you do not need.

Note: Package names are not always identical across distributions. A package on Ubuntu may use a different name on Fedora or RHEL.

Snap and AppImage Basics

Traditional distro packages are not the only way to distribute Linux software.

Snap

Snap packages bundle applications in a more self-contained format.

sudo snap install code --classic
snap list
sudo snap remove code

Snaps are convenient across distributions, but they may use more disk space or start more slowly because more dependencies are bundled.

AppImage

An AppImage is usually one executable file that you download and run directly.

chmod +x MyTool.AppImage
./MyTool.AppImage

This is simple, but updates and lifecycle management are less centralized than with APT or DNF.

Holding or Pinning Versions

Sometimes you do not want the latest version immediately. Production systems may depend on a known-good release, or you may want to delay an upgrade until testing is complete.

Holding packages with APT

sudo apt-mark hold nginx
sudo apt-mark unhold nginx

A held package is skipped during normal upgrades.

APT can also use preference files under /etc/apt/preferences.d/ for stronger pinning rules when administrators need to prefer a specific version or repository.

Controlling versions with DNF

On RHEL style systems, administrators often manage versions through repository policy, explicit version installs, or the versionlock plugin when it is available.

sudo dnf install nginx-1.24.0
sudo dnf versionlock add nginx

Exact version locking support depends on the distribution and plugins installed, so it is worth checking your environment.

A Practical Workflow

Imagine you are preparing a VM for a web service. On Ubuntu you might do:

sudo apt update
sudo apt install nginx curl git
apt list --installed | grep nginx

On Fedora or RHEL you might do:

sudo dnf install nginx curl git
sudo dnf update

The details differ, but the logic stays the same:

  • refresh metadata when needed
  • install packages from trusted sources
  • remove unneeded software
  • keep version control in mind for stable systems

What You Should Remember

APT and DNF solve the same problem on different Linux families: managing software packages and dependencies. Snap and AppImage provide alternative distribution models, but repository-based package management remains central on most servers.

As you move into automation and operations, package management becomes part of repeatable infrastructure rather than one-off software installation.

Test Your Understanding

Exercise

Exercise 1: Refreshing package metadata

Which APT command refreshes the local package index without upgrading installed packages?

Exercise

Exercise 2: Removing leftover dependencies

After uninstalling a package on Ubuntu, which command is commonly used to remove dependencies that are no longer needed?

Exercise

Exercise 3: Understanding AppImage

What best describes an AppImage in Linux?


Frequently Asked Questions

What is the difference between apt and apt-get?

apt is the newer command intended for interactive use: it has progress bars, colour, and combines the most common operations from apt-get and apt-cache in one place. apt-get has a stable, guaranteed-unchanging interface, which is why scripts and Dockerfiles should use it, apt prints a warning about unstable CLI behaviour when run non-interactively. Use apt at a terminal and apt-get in automation.

What is the difference between apt remove, purge and autoremove?

remove uninstalls the package but leaves its configuration files in place, so reinstalling restores your settings. purge removes the configuration too, which is what you want when a broken config is the reason you are reinstalling. autoremove deletes packages that were pulled in as dependencies and are no longer needed by anything. Worth running occasionally, and worth reading the list first, because it occasionally proposes removing something you installed indirectly but do want.

Why does apt install fail with "Unable to locate package"?

Usually a stale package index. apt-get update refreshes the metadata, and install then finds the package. This is exactly why update and install must share a single RUN in a Dockerfile, or the cached index goes stale. If it still fails after updating, the package is genuinely not in your configured repositories: check the spelling with apt-cache search <name>, and check whether it needs a PPA, a third-party repository or a different name on your distribution.

How do I fix "could not get lock /var/lib/dpkg/lock-frontend"?

Another process holds the package manager lock, usually an automatic update running in the background, or a previous command that was interrupted. Wait a minute and retry, since unattended-upgrades finishes on its own. If nothing is running, sudo lsof /var/lib/dpkg/lock-frontend names the holder. Deleting the lock file is the advice you will find online and is a last resort: do it only after confirming no apt or dpkg process exists, then run sudo dpkg --configure -a to repair any half-finished state.

What is the difference between dnf, yum and rpm?

rpm is the low-level package format and tool: it installs a single .rpm file and will not resolve dependencies for you. yum was the dependency-resolving package manager built on top of it, and dnf is its rewritten successor, on current RHEL, CentOS Stream and Fedora, yum is a symlink to dnf and the two are interchangeable. Use dnf for anything from a repository, and rpm -qa, rpm -ql and rpm -qf for querying what is installed and which package owns a file.

Should I use snap, flatpak or the distribution's packages?

Distribution packages first: they are smaller, start faster, integrate with the system, and receive security updates through the channel you already monitor. Snap and Flatpak bundle their dependencies, which makes them useful for desktop applications that need newer libraries than your release ships, at the cost of size and slower first launch. On a server, prefer the distribution's packages or containers. Snaps auto-update on their own schedule, which is rarely what you want on infrastructure.

Continue Learning

Explore Related Topics

Try the Tool

Practise this in the browser

Linux Playground

Practise real shell commands in a simulated terminal.

When it breaks

Related Resources