Linux Package Management
Learn how to install, update, remove, and manage software packages with APT, DNF, Snap, and AppImage on Linux.
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 updatefirst, 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 1: Refreshing package metadata
Which APT command refreshes the local package index without upgrading installed packages?
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 3: Understanding AppImage
What best describes an AppImage in Linux?