Computing Foundations › The Command Line › Day 13

Day 13: Package Managers: Homebrew, apt, and winget

Day 13 of 365 — Package Managers: Homebrew, apt, and winget

After this lesson you will be able to explain what a package manager does, use Homebrew, apt, or winget to install and manage software, and understand how manifests and version pinning make an environment reproducible on any machine.

Course
Computing Foundations
Category
The Command Line
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-013-package-managers-homebrew-apt-and-winget

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/computing-foundations/day-013-package-managers-homebrew-apt-and-winget
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters


The idea in plain language

Diagram: installing software manually compared with using a package manager


Historical background


What it is — and what it is not

Diagram: how a package manager connects you to a remote repository and installs software locally with its dependencies

Four parts do the work:

It is not:


Why it was created and what problems it solves

Diagram: how requesting one package pulls in its dependency tree


How it works

Diagram: refreshing the package index compared with upgrading installed packages

Manifests and lock files

Diagram: a dependency manifest compared with a lock file

The commands, per manager

# macOS — Homebrew
brew search wget && brew install wget
brew list && brew upgrade && brew uninstall wget

# Debian, Ubuntu — apt
sudo apt update              # refresh the LOCAL copy of the index first
apt search wget && sudo apt install wget
apt list --installed && sudo apt upgrade && sudo apt remove wget
# Windows — winget
winget search wget
winget install wget
winget list; winget upgrade --all; winget uninstall wget

One layer down: pip and npm


An everyday analogy

Diagram: installing language packages system-wide compared with in an environment

A well-run library.

The libraryThe package manager
The catalogueThe repository index
The shelvesThe repository
Your borrowing recordThe local database
”This book cites three others”Dependencies
A reading list you wroteThe manifest
The stamped record of what you tookThe lock file
The returns deskClean uninstallation

Examples in practice

Flowchart: the five stages of installing one package — resolve, download, verify, install, record


Implications: security, privacy, performance, scalability, and cost


Alternatives: free, open source, and commercial

Diagram: a cold install compared with one served from cache

ToolTypeWhere it fits
Homebrew / apt / wingetFreeWhole programs, per operating system
pip, npm, cargoFreeLanguage libraries, per ecosystem
conda / mambaFreeScientific stacks, including non-Python dependencies
uv, poetryFree, open sourceFaster, stricter Python dependency resolution
DockerFree, open sourceWhen the environment itself must travel
NixFree, open sourceFully reproducible builds, at a real learning cost

TermWhat it actually is
PackageA program’s files plus metadata about them
RepositoryA curated collection the manager can reach
IndexThe catalogue of packages, versions and dependencies
DependencySomething a package needs to run
ManifestWhat you asked for
Lock fileWhat you actually got, exactly
MirrorA duplicate repository, hosted nearer you

When to use it — and when not to

Diagram: Homebrew compared with apt and winget


The AI connection

Diagram: the layered version dependencies of a GPU machine learning stack

Diagram: the trust risks of installing packages and the habits that reduce them


Knowledge check

quiz:
  question: "A project installs cleanly today and fails on a colleague's machine next week, with no code changes in between. Which file, if committed, would most likely have prevented this?"
  options:
    - "The lock file, which records the exact resolved versions of every dependency"
    - "The manifest, which lists the packages the project needs"
    - "The repository index, which catalogues available versions"
    - "The local package database, which records what is installed on the machine"
  answer_index: 0
  explanation: "The manifest was already there — it says what is needed, loosely. Between the two installs a dependency released a new version that still satisfied the manifest, and only the lock file pins the exact versions that were known to work."

Hands-on exercise

Install something, inspect what came with it, then remove it cleanly. Worked through fully in the Day 13 lab directory.

What you are doingCommand (macOS / Debian)
Refresh the indexbrew update / sudo apt update
Search for a packagebrew search jq / apt search jq
See what it will pull inbrew deps jq / apt-cache depends jq
Install itbrew install jq / sudo apt install jq
Find where it landedcommand -v jq
List what is installedbrew list / apt list --installed | head
Remove itbrew uninstall jq / sudo apt remove jq

Expected output

==> Fetching dependencies for jq: oniguruma
==> Installing jq
/opt/homebrew/bin/jq
jq-1.7.1

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. What is the single hardest job a package manager does for you?

  1. Downloading a file faster than a web browser can
  2. Displaying user ratings and written reviews before you install anything
  3. Writing the source code of the program being installed
  4. Resolving dependencies and installing them in the right order
Show answer

Answer: D. Resolving dependencies and installing them in the right order

Almost no program is self-contained; each package lists what it depends on, and the manager reads those descriptions to compute and install the complete dependency tree in a valid order — the work that manual installation gets wrong.

Q2. Which sequence correctly orders the five stages of installing one package?

  1. Resolve, download, verify, install, record
  2. Download, resolve, install, verify, record
  3. Verify, download, resolve, record, install
  4. Install, resolve, download, record, verify
Show answer

Answer: A. Resolve, download, verify, install, record

The manager first resolves the full set of required packages from the index, downloads them, verifies their integrity, installs them in dependency order, and finally records the installation in its local database.

Q3. What is the difference between a manifest and a lock file?

  1. A manifest is written by the manager; a lock file is written by you
  2. A manifest says what you want; a lock file says what you got
  3. They are two names for the same file
  4. A manifest is for macOS and a lock file is for Windows
Show answer

Answer: B. A manifest says what you want; a lock file says what you got

The manifest captures human intent (often loosely, e.g. "a spreadsheet library"), while the lock file records the precise resolved versions of everything installed, which is what makes an install reproducible on another machine.

Q4. Which is the correct default command to install a package called wget on Debian/Ubuntu?

  1. brew install wget
  2. winget install wget
  3. sudo apt install wget
  4. pip install wget
Show answer

Answer: C. sudo apt install wget

apt is the default system package manager on Debian-based Linux, and because it installs system-wide its changing commands need administrator rights via sudo. Homebrew (brew) is for macOS and winget is for Windows.

Q5. Why does apt ask you to run "apt update" before installing?

  1. It upgrades every installed package to a newer version
  2. It is required to give the terminal full administrator rights on the system
  3. It creates a manifest file for your project
  4. It refreshes the local repository index so apt sees current versions
Show answer

Answer: D. It refreshes the local repository index so apt sees current versions

apt resolves against its local copy of the repository index; "apt update" refreshes that copy so you install current versions. (Note that "apt upgrade", a different command, is the one that actually upgrades installed packages.)

Q6. What does version pinning protect you from?

  1. Silent upgrades that change which version a project runs
  2. Running out of disk space during installation
  3. Downloading packages over a slow network connection
  4. Installing software without administrator rights
Show answer

Answer: A. Silent upgrades that change which version a project runs

Pinning requests a specific version rather than "the latest," so a dependency cannot quietly move to a new version and change how your project behaves — the usual cause of "it works on my machine" failures.

Q7. Why is installing from a package manager's official repository generally safer than downloading an installer from a search result?

  1. The manager scans your entire hard drive for viruses before installing
  2. Repositories are curated and each download's checksum is verified
  3. Package managers make software run faster once installed
  4. Downloaded installers can never contain useful software
Show answer

Answer: B. Repositories are curated and each download's checksum is verified

Managers fetch from curated repositories over verified channels and check integrity before installing, closing off tampered or corrupted downloads — a real security improvement, though the trust chain weakens if you add untrusted third-party repositories.

Q8. How does a lock file support reproducibility at scale, across many machines?

  1. It stores a compressed backup of the operating system
  2. It automatically buys more servers when needed
  3. It records exact versions so the environment can be rebuilt
  4. It prevents any software from ever being upgraded again
Show answer

Answer: C. It records exact versions so the environment can be rebuilt

Because the lock file freezes exact versions as plain text, the same specification provisions one machine or a whole fleet identically; without it, "install the latest" run on different days yields many slightly different, hard-to-debug environments.

Glossary

package
A bundle of a program's files together with metadata describing what it is, its version, and what other software it depends on — the unit a package manager installs, updates, and removes.
package manager
A program whose job is to install, upgrade, and remove software from curated repositories, automatically resolving dependencies and keeping a local record of everything it has done.
repository
A curated online collection of packages, plus an index of their versions and dependencies, that a package manager knows how to reach and trust.
dependency
Other software a package needs installed first in order to run; the branching chain of these is what a package manager resolves automatically.
dependency resolution
The process of reading each package's requirements and computing the complete set of packages needed, in an order where nothing is missing when it is used.
Homebrew
The popular free, open-source package manager for macOS (and Linux), driven by the brew command; its packages are called formulae.
apt
The Advanced Package Tool, the default package manager on Debian and Ubuntu Linux, which resolves dependencies and installs system-wide packages (usually run with sudo).
winget
The Windows Package Manager, Microsoft's first-party command-line tool for installing, upgrading, and removing software on Windows 10 and 11.
manifest
A file you write that lists the packages a project needs — its stated intent — turning "install everything this needs" into one shareable, repeatable command.
lock file
A file written by the manager recording the exact versions of every package actually installed, so another machine can rebuild the identical environment.
version pinning
Requesting a specific version of a package rather than "the latest," so a silent upgrade cannot change a project's behavior.
upgrade
Moving installed software to a newer version while preserving the surrounding dependency tree, as opposed to reinstalling the same version.
mirror
A synchronized duplicate of a repository hosted elsewhere, providing faster and more reliable downloads and redundancy.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.