Practical Professional Linux — Foundation

Chapter 6 · Skill Level: Foundation

Package & Software Management

Install, update, and remove software safely using each distribution’s package manager.

Software on Linux is delivered through package managers that handle dependencies, integrity, and security updates. This chapter covers the two dominant families and the principles that apply to both.

By the end of this chapter you will be able to

  • Use apt and dnf to manage the package lifecycle.
  • Explain repositories, signing, and dependency resolution.
  • Apply security updates correctly.
  • Differentiate system packages from Snap/Flatpak.
  • Decide when (rarely) to build from source.

6.1 Package Managers by Family

Task Ubuntu/Debian (apt) → Rocky/Alma/RHEL (dnf)
Refresh lists sudo apt update → (dnf refreshes automatically)
Install sudo apt install pkg → sudo dnf install pkg
Remove sudo apt remove pkg → sudo dnf remove pkg
Update all sudo apt upgrade → sudo dnf upgrade
Search apt search term → dnf search term
Info apt show pkg → dnf info pkg

6.2 Installing Software

Installing a package
# Ubuntu: always refresh first, then install
sudo apt update && sudo apt install -y nginx
 
# Rocky/Alma:
sudo dnf install nginx

6.3 Updates and Patching

Most security incidents exploit known, already-patched bugs. Keeping packages current is one of the highest-value things you can do.

Applying updates
# Ubuntu
sudo apt update && sudo apt upgrade -y
 
# Rocky/Alma
sudo dnf upgrade -y
 
# See what would change first (Ubuntu):
apt list --upgradable

6.4 Removing and Cleaning

Removing packages
sudo apt remove cowsay      # remove, keep config
sudo apt purge cowsay       # remove + config files
sudo apt autoremove         # drop unused dependencies
 
sudo dnf remove cowsay      # RHEL-family

6.5 Snap, Flatpak, and Source Builds

Beyond system packages, Snap and Flatpak ship self-contained apps that work across distributions, useful for desktop software. Building from source (./configure && make && sudo make install) is a last resort when no package exists.

6.6 Guided Lab: Package Lifecycle

Estimated time: 20 minutes. Search, install, inspect, update, and remove a package end to end.

  • Refresh package lists (Ubuntu: sudo apt update).
  • Search for a tool: apt search tree (or dnf search tree).
  • Install it: sudo apt install -y tree (or sudo dnf install tree).
  • Confirm it works: run tree -L 1 ~.
  • Show package details: apt show tree (or dnf info tree).
  • Check for available updates, then remove the tool with purge/remove and autoremove.

Troubleshooting

Symptom Likely cause and fix
‘Could not get lock’ / another apt process A previous apt is still running or crashed. Wait, or remove stale locks only if you’re sure no apt is running; then sudo dpkg –configure -a.
‘Unable to locate package’ Lists are stale or the name differs. Run apt update; check the exact name (apache2 on Ubuntu vs httpd on RHEL).
Broken dependencies after a manual .deb Avoid manual installs; fix with sudo apt -f install. Prefer the repo version.
Update breaks a service Roll back to the previous package version if available, or restore from a pre-update snapshot. Test updates in staging first.

Practice & Prove It

Write-the-command drills

  • On Ubuntu, refresh lists and install git in one command.
  • On Rocky/Alma, install the nano editor.
  • Show detailed information about the openssh-server package (Ubuntu).
  • Upgrade all packages on Ubuntu non-interactively.
  • Completely remove the package ‘cowsay’ including its config (Ubuntu).

Quick quiz

  • Which command refreshes package lists on Ubuntu?
  • Why install from official repositories?
  • What is the RHEL-family equivalent of apt install?
  • What does apt autoremove do?
  • When is building from source appropriate?

Key Takeaways

  • Package managers install signed, dependency-resolved software in one command.
  • apt (Ubuntu/Debian) and dnf (Rocky/Alma/RHEL) share the same concepts.
  • Always refresh lists before installing; install from official repos, not random files.
  • Keeping packages patched closes the majority of real-world vulnerabilities.
  • Use purge/autoremove to clean up; build from source only as a last resort.

Next — Chapter 7: process management — observing, signalling, and prioritising running programs.