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.
What You'll Learn
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 .
🎯 Your Turn: install with APT
Fill in the two blanks marked ______ using the # 👉 hints. Remember which apt subcommand refreshes the lists and which one installs.
🎯 Your Turn: match the manager
Two blanks again: the pacman flag that installs on Arch, and the command name you use on macOS (with no sudo).
Pro Tips
- 💡 Update before you install: on APT, run sudo apt update first so you install the newest version available — then sudo apt install <pkg> .
- 💡 Install several at once: every manager takes a list — sudo apt install git curl htop or sudo pacman -S git curl htop .
- 💡 Never sudo Homebrew, pip, or npm: brew owns its own prefix, and language managers work per-user/project. Using sudo with them invites permission breakage.
- 💡 Search before you guess: apt search <term> , dnf search <term> , pacman -Ss <term> , or brew search <term> to find the exact package name.
Common Errors (and the fix)
- "Permission denied" / "are you root?" — a system manager needs root. Prefix the command with sudo (e.g. sudo apt install ... ). The exception is Homebrew, which must not use sudo.
- "Unable to locate package" on APT — your lists are stale or the name is wrong. Run sudo apt update first, and check the spelling with apt search <term> .
- "apt update did nothing" — that's expected: apt update only refreshes the lists. To install the new versions, run sudo apt upgrade .
- "sudo brew" warns or breaks things — don't use sudo with Homebrew. If you already did and permissions are off, see brew doctor .
- Reaching for sudo pip / sudo npm — these are language/project managers, not system managers. Install per-user or in a project/virtual environment instead of using sudo.
📋 Quick Reference
System
Install
Remove
Update / Upgrade
Search
Debian/Ubuntu (apt)
sudo apt install x
sudo apt remove x
sudo apt update / upgrade
apt search t
Fedora/RHEL (dnf)
sudo dnf install x
sudo dnf remove x
sudo dnf update
dnf search t
Arch (pacman)
sudo pacman -S x
sudo pacman -R x
sudo pacman -Syu
pacman -Ss t
macOS (brew, no sudo)
brew install x
brew uninstall x
brew update / upgrade
brew search t
Language libs (no sudo)
pip / npm / gem install
pip / npm / gem uninstall
per project / user
on the registry
Frequently Asked Questions
Mini-Challenge: new-machine setup
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 .
🎉 Lesson Complete!
- ✅ A package manager installs, updates, and removes software and resolves dependencies from repositories
- ✅ Debian/Ubuntu use apt : apt update refreshes the lists, apt upgrade applies them
- ✅ Fedora/RHEL use dnf (older: yum ); Arch uses pacman ( -S , -R , -Syu , -Ss )
- ✅ macOS uses brew — and it does not need sudo , because it owns its own prefix
- ✅ pip, npm, and gem are language/project managers, not system managers — avoid sudo with them
- ✅ Next lesson: SSH and Remote Access — log in to and run commands on other machines securely
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.
Continue this course
- Previous: Processing JSON with jq
- Next: SSH and Remote Access