Package Managers
By the end of this lesson you'll be able to install, update, and remove software from the command line on any major system — Debian/Ubuntu (apt), Fedora/RHEL (dnf), Arch (pacman), and macOS (Homebrew) — and you'll know why some managers need sudo and others (like pip and npm) do not.
Learn Package Managers in our free Command Line course — an interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Cli course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
1. What a Package Manager Is
A package manager installs, updates, and removes software for you, and — crucially — it resolves dependencies . A package is bundled software plus metadata (its name, version, and what it needs); a dependency is another package it relies on. The manager pulls everything from repositories (online catalogs of packages), so you install a program by name without chasing down installers yourself. Every manager does the same four jobs: install , remove , update/upgrade , and search — only the command name changes.
2. Debian & Ubuntu: APT
Debian, Ubuntu, and Mint use APT . The one rule beginners trip on: sudo apt update only refreshes the package index (the lists of what's available) — it does not install anything. To actually apply the new versions you run sudo apt upgrade . So the everyday pattern is "update, then upgrade." Install and remove single packages with sudo apt install <pkg> and sudo apt remove <pkg> .
3. Fedora & RHEL: dnf (and yum)
Fedora, RHEL, CentOS, and Rocky use dnf , the modern replacement for the older yum (the two share almost identical commands, so yum often still works). Install with sudo dnf install <pkg> , remove with sudo dnf remove <pkg> , update everything with sudo dnf update , and look things up with dnf search <term> .
4. Arch Linux: pacman
Arch Linux and Manjaro use pacman , which uses short flags: -S to sync/install , -R to remove , -Syu to refresh the lists and upgrade everything at once, and -Ss to search . So sudo pacman -S firefox installs Firefox, and sudo pacman -Syu is the standard "update my whole system" command.
5. macOS: Homebrew
macOS commonly uses Homebrew , invoked as brew . Install with brew install <pkg> , remove with brew uninstall <pkg> , refresh Homebrew and its formula lists with brew update , and upgrade what's installed with brew upgrade . Unlike the Linux managers, Homebrew installs into its own prefix that your user owns , so it does not need sudo — and running sudo brew can actually break your install.
6. System Managers vs. Language/Project Managers
There are two layers, and mixing them up causes real trouble. System managers — apt, dnf, pacman, brew — install programs for the whole machine and (except brew) need sudo . Language/project managers — pip (Python), npm (Node), gem (Ruby) — install code libraries for one language, usually per-project or per-user. They are not system package managers and generally should not be run with sudo . Rule of thumb: apt/dnf/pacman/brew install programs ; pip/npm/gem install libraries .
Fill in the two blanks marked ______ using the # 👉 hints. Remember which apt subcommand refreshes the lists and which one installs.
Two blanks again: the pacman flag that installs on Arch, and the command name you use on macOS (with no sudo).
No blanks this time — just a brief. Write the commands to install git, curl, and htop on three platforms (Ubuntu with apt, Arch with pacman, macOS with Homebrew), and add a comment explaining why only the macOS line skips sudo .
Practice quiz
What is a package manager's main job?
- Installs, updates, and removes software while resolving its dependencies
- Edits text files
- Compiles your own source code
- Manages user passwords
Answer: Installs, updates, and removes software while resolving its dependencies. A package manager installs, updates, and removes software and automatically pulls in the dependencies each package needs from configured repositories.
Which command installs a package on Debian/Ubuntu?
- yum install git
- apt get package
- sudo apt install git
- apt download git
Answer: sudo apt install git. On Debian and Ubuntu you install with sudo apt install <pkg>, for example sudo apt install git.
What does 'sudo apt update' actually do?
- Removes unused packages
- Refreshes the list of available packages
- Upgrades the Linux kernel
- Installs all pending upgrades
Answer: Refreshes the list of available packages. apt update only refreshes the local package index (the lists of what is available). It does NOT install anything; use apt upgrade for that.
Which command upgrades all installed packages on Ubuntu?
- sudo apt refresh
- sudo apt update
- sudo apt fix
- sudo apt upgrade
Answer: sudo apt upgrade. sudo apt upgrade applies the upgrades. apt update only refreshes the lists; you typically run update first, then upgrade.
Which package manager does Arch Linux use?
- pacman
- apt
- dnf
- brew
Answer: pacman. Arch Linux uses pacman. For example sudo pacman -S <pkg> installs a package.
Which command installs a package on Arch Linux with pacman?
- sudo pacman -R firefox
- sudo pacman -S firefox
- sudo pacman -Q firefox
- sudo pacman get firefox
Answer: sudo pacman -S firefox. pacman -S syncs/installs a package, so sudo pacman -S firefox installs Firefox. -R removes a package.
Which package manager is used on macOS?
- dnf
- apt
- pacman
- Homebrew (brew)
Answer: Homebrew (brew). Homebrew, invoked as brew, is the popular package manager for macOS (for example brew install wget).
Does Homebrew require sudo to install packages?
- Only on Linux
- Yes, for every command
- No
- Yes, always
Answer: No. Homebrew installs into its own prefix that your user owns, so you should NOT use sudo with brew. System managers like apt do need sudo.
pip and npm are examples of what?
- System package managers like apt
- Language/project package managers, not system package managers
- Linux distributions
- Text editors
Answer: Language/project package managers, not system package managers. pip (Python) and npm (Node) install language libraries per project or per user. They are language/project managers, not system package managers, and generally do not need sudo.
On Fedora or RHEL, which command installs a package?
- sudo dnf install httpd
- sudo pacman -S httpd
- brew install httpd
- sudo apt install httpd
Answer: sudo dnf install httpd. Fedora and RHEL use dnf (the older name is yum), so sudo dnf install httpd installs the package.