← Linux from ScratchCheat sheet
M16Linux from Scratch

M16 — Software packages (apt and dnf)

Time: about 40–60 minutes
Lab root: Your disposable VM (apt or dnf); demos also used /tmp/linux-lab-pushpjeet

Linux distributions ship a package manager: a trusted way to search, install, update, and remove software. On Debian/Ubuntu-family systems that tool is apt. On Fedora/RHEL-family systems (including many cloud images and Oracle Linux in shops that use it as one RHEL-compatible option) the modern tool is dnf.

This module teaches both side by side. Learn the idea once; swap the command for the distro in front of you.

Prerequisites#

  • Root or sudo on a practice VM (do not practice removals on a production laptop without a snapshot).
  • M2-level comfort with the terminal.

Learning objectives#

  1. Explain package, repository, and dependency in plain language.
  2. Search, install, verify, update, and remove software with apt and dnf.
  3. Read a short “same job, two commands” table without memorizing only one family.
  4. Install a small utility (tree or htop) on a disposable VM and remove it cleanly.

Which manager do I have?#

. /etc/os-release
echo "$PRETTY_NAME"
command -v apt && echo "→ use apt columns"
command -v dnf && echo "→ use dnf columns"

Drafting box: Debian GNU/Linux 13 (trixie) with apt only. All apt outputs below are from that box on 2026-09-26 IST. dnf lines are the standard Fedora/RHEL-family equivalents for you to run where dnf exists.


1. Mental model#

Term Meaning
Package A named, versioned bundle (binary + metadata + deps), e.g. tree
Repository A signed collection of packages your distro knows about
Dependency Other packages this one needs; the manager installs them too
Update metadata Refresh the local index of what the repos offer
Upgrade Install newer versions of already-installed packages

You rarely download random .deb / .rpm files from the web when starting out — use the manager so signatures and dependencies stay consistent.


2. Side-by-side command map#

Job Debian / Ubuntu (apt) Fedora / RHEL-family (dnf)
Refresh package index sudo apt update sudo dnf check-update (or sudo dnf makecache)
Upgrade installed pkgs sudo apt upgrade sudo dnf upgrade
Search by name/keyword apt search tree dnf search tree
Show package details apt show tree dnf info tree
Install sudo apt install tree sudo dnf install tree
Remove sudo apt remove tree sudo dnf remove tree
Remove + unused deps sudo apt autoremove sudo dnf autoremove
List installed (sample) apt list --installed dnf list installed
Which package owns a file? dpkg -S $(command -v tree) rpm -qf $(command -v tree)

Notes:

  • On older RHEL-family systems you may still see yum; on current releases dnf is the front end (often yum is an alias).
  • Oracle Linux, AlmaLinux, Rocky Linux, CentOS Stream → think dnf family.
  • Ubuntu, Debian, Linux Mint, Pop!_OS → think apt family.

3. apt walk-through (executed on Debian 13)#

apt-cache search '^tree$'
# or: apt search '^tree$'

Lab output:

tree - displays an indented directory tree, in color

Policy / candidate version#

apt-cache policy tree

Lab output (abridged):

tree:
  Installed: (none)
  Candidate: 2.2.1-1
  Version table:
     2.2.1-1 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages

Install (needs sudo)#

sudo apt update
sudo apt install -y tree
tree --version | head -1

Lab verify: tree v2.2.1 …

tree -L 2 /tmp/linux-lab-pushpjeet/m15/project

Lab output:

/tmp/linux-lab-pushpjeet/m15/project
├── config.ini
├── docs
│   └── readme.md
└── src
    └── app.py

3 directories, 3 files

Remove#

sudo apt remove -y tree

After removal, tree is gone from the PATH; the package can be installed again later the same way.


4. dnf walk-through (run on a Fedora/RHEL-family VM)#

sudo dnf search tree
sudo dnf info tree
sudo dnf install -y tree
tree --version
sudo dnf remove -y tree

Same learning goals, different verb spelling. If you use both Ubuntu at home and RHEL at work, keep the section 2 table nearby for a week — then it sticks.


5. Good habits#

  1. Snapshot or disposable VM before mass upgrades.
  2. Prefer apt install / dnf install over pasting untrusted install scripts.
  3. Read what will be removed when you remove a package that looks “small” but pulls a desktop stack — the manager shows the plan; say no if surprised.
  4. After experiments: autoremove unused dependencies.
  5. For servers, pin critical versions only when you know why (advanced; not required here).

Common mistakes#

Mistake Fix
Running apt install without update on a stale VM sudo apt update first
Memorizing only apt then freezing on a RHEL box Keep the side-by-side table
Installing as root without looking at the package list Read the summary; abort if huge/unexpected
Confusing apt update with apt upgrade update = indexes; upgrade = install newer packages
Using pip install for OS-level tools like ping Prefer the distro package manager for system utilities

Hands-on lab (30–45 minutes)#

Use your practice VM (WSL, cloud, or VirtualBox). Pick the column that matches your distro.

Tasks#

  1. Identify the manager (apt or dnf).
  2. Update metadata.
  3. Search for tree and htop.
  4. Install one of them (tree recommended).
  5. Run it against a directory you know.
  6. Remove it again.
  7. (Optional) Install rsync and openssh-client if M15 needed them.

Verify#

  • Before install: command not found (or old version noted).
  • After install: command -v tree prints a path; --version works.
  • After remove: command not found again.

Practice: check your understanding#

Multiple choice#

Q1. On Ubuntu, which command installs htop?

  • A. sudo dnf install htop
  • B. sudo apt install htop
  • C. tar -xzf htop
  • D. chmod +x htop

Answer: B.

Q2. What does refreshing the package index do?

  • A. Deletes unused home directories
  • B. Updates the local list of available packages/versions from repositories
  • C. Reboots the kernel
  • D. Compresses /var/log

Answer: B.

Q3. Fedora / RHEL-family systems typically use:

  • A. apt only
  • B. dnf (with yum often as compatibility)
  • C. brew as the system manager
  • D. pip for all OS tools

Answer: B.

Flashcards#

Front Back
apt Debian/Ubuntu package manager front end
dnf Fedora/RHEL-family package manager
sudo apt update Refresh apt package indexes
sudo dnf upgrade Upgrade installed packages (dnf)
Dependency Other package required by the one you install
Repository Signed collection of packages
apt show / dnf info Detailed metadata for one package
autoremove Clear leftover unused dependencies

Match the columns — apt ↔ dnf#

apt dnf counterpart
sudo apt update sudo dnf check-update / makecache
sudo apt upgrade sudo dnf upgrade
apt search tree dnf search tree
sudo apt install tree sudo dnf install tree
sudo apt remove tree sudo dnf remove tree
apt show tree dnf info tree

Fill in the blank#

  1. Debian install: sudo apt _______ tree
    Answer: install

  2. RHEL-family install: sudo dnf _______ tree
    Answer: install

  3. Refresh apt indexes: sudo apt _______
    Answer: update

  4. Remove on Fedora: sudo dnf _______ tree
    Answer: remove

Order the steps — install tree safely#

  1. Confirm you are on a practice VM / have a snapshot
  2. sudo apt update or sudo dnf check-update
  3. Search so the name is correct (tree not a random lookalike)
  4. sudo apt install tree or sudo dnf install tree
  5. Verify with tree --version and a quick tree -L 1 …
  6. (Lab only) Remove when finished

Correct order: 1 → 2 → 3 → 4 → 5 → 6

Mini terminal challenge#

Challenge: Install tree#

Goal: Install, use, remove tree with your distro’s manager.

Setup: Disposable VM with sudo.

Tasks:

  1. Update indexes.
  2. Install tree.
  3. Run tree -L 2 on any project directory.
  4. Remove tree.

Verify: Steps 3 works; after step 4, command -v tree is empty.

Stretch: Install htop, run it once (F10 to quit), remove it.


Module wrap#

You can search, install, verify, and remove packages on both Debian/Ubuntu (apt) and Fedora/RHEL-family (dnf) systems. Next: accounts and groups (M17).


Continue

← Linux from Scratch hub · Cheat sheet · All tutorials