Prerequisites#
- Root or
sudoon a practice VM (do not practice removals on a production laptop without a snapshot). - M2-level comfort with the terminal.
Learning objectives#
- Explain package, repository, and dependency in plain language.
- Search, install, verify, update, and remove software with apt and dnf.
- Read a short “same job, two commands” table without memorizing only one family.
- Install a small utility (
treeorhtop) 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 releasesdnfis the front end (oftenyumis 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)#
Search#
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#
- Snapshot or disposable VM before mass upgrades.
- Prefer
apt install/dnf installover pasting untrusted install scripts. - Read what will be removed when you
removea package that looks “small” but pulls a desktop stack — the manager shows the plan; say no if surprised. - After experiments:
autoremoveunused dependencies. - 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#
- Identify the manager (
aptordnf). - Update metadata.
- Search for
treeandhtop. - Install one of them (
treerecommended). - Run it against a directory you know.
- Remove it again.
- (Optional) Install
rsyncandopenssh-clientif M15 needed them.
Verify#
- Before install: command not found (or old version noted).
- After install:
command -v treeprints a path;--versionworks. - 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.
aptonly - B.
dnf(withyumoften as compatibility) - C.
brewas the system manager - D.
pipfor 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#
-
Debian install:
sudo apt _______ tree
Answer:install -
RHEL-family install:
sudo dnf _______ tree
Answer:install -
Refresh apt indexes:
sudo apt _______
Answer:update -
Remove on Fedora:
sudo dnf _______ tree
Answer:remove
Order the steps — install tree safely#
- Confirm you are on a practice VM / have a snapshot
sudo apt updateorsudo dnf check-update- Search so the name is correct (
treenot a random lookalike) sudo apt install treeorsudo dnf install tree- Verify with
tree --versionand a quicktree -L 1 … - (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:
- Update indexes.
- Install
tree. - Run
tree -L 2on any project directory. - 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).