Package Managers
Reviewed & published by Brayan K
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.
Part of the free Command Line course at LearnCodingFast — hands-on lessons with worked examples and the output they print, plus practice exercises and a quick quiz.
What You'll Learn
- What a package manager does: install, update, remove, and resolve dependencies from repositories
- Debian/Ubuntu with APT: apt update vs apt upgrade, install, remove, search, show
- Fedora/RHEL with dnf (and yum), and Arch with pacman (-S, -R, -Syu, -Ss)
- macOS with Homebrew: brew install / uninstall / update / upgrade — and no sudo
- Why system managers need sudo but Homebrew does not
- How system managers differ from language/project managers like pip, npm, and gem
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>.
# Debian & Ubuntu use APT. Most actions touch system directories,
# so they need root — that is what 'sudo' is for.
# 1) Refresh the package index (the lists of what is available).
# This does NOT install or upgrade anything by itself.
sudo apt update
# 2) Apply available upgrades to everything already installed.
sudo apt upgrade
# 3) Install a package and everything it depends on.
sudo apt install git
# 4) Remove a package you no longer want.
sudo apt remove git
# Search and inspect (no sudo needed — just reading):
apt search compression # find packages matching a term
apt show git # show details about one package3. 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>.
# Fedora, RHEL, CentOS and Rocky use DNF (the older tool was YUM;
# the commands line up almost one-to-one, so 'yum' often still works).
sudo dnf install httpd # install the Apache web server + deps
sudo dnf remove httpd # remove it again
sudo dnf update # update installed packages (refresh + upgrade)
dnf search webserver # search available packages (no sudo needed)
# Older systems (or muscle memory) — same idea with yum:
sudo yum install httpd4. 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.
# Arch Linux (and Manjaro) use pacman. Its flags are terse but logical:
# -S Sync/install -R Remove -Ss Search -Syu refresh + upgrade
sudo pacman -S firefox # install a package (and its dependencies)
sudo pacman -R firefox # remove a package
sudo pacman -Syu # refresh the lists AND upgrade everything
pacman -Ss editor # search available packages (no sudo needed)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.
# macOS uses Homebrew, invoked as 'brew'. Homebrew installs into its
# OWN prefix that your user owns, so you do NOT (and should not) use sudo.
brew install wget # install a package (called a "formula")
brew uninstall wget # remove it
brew update # update Homebrew itself + the formula lists
brew upgrade # upgrade the packages you have installed
brew search image # search for available formulae
# Notice: NO 'sudo' anywhere above. If a guide tells you to 'sudo brew',
# that is a red flag — it can break the permissions of 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.
# Two DIFFERENT layers. Do not mix them up.
# (A) SYSTEM package managers — install software for the whole machine,
# write to system directories, and therefore need sudo (except brew).
sudo apt install python3 # the Python interpreter itself
sudo dnf install nodejs # Node.js, system-wide
# (B) LANGUAGE / PROJECT managers — install libraries for ONE language,
# usually per-project or per-user. They are NOT system managers and
# generally do NOT need sudo (in fact, avoid sudo with them).
pip install requests # a Python library (use a virtualenv)
npm install express # a Node library, into ./node_modules
gem install bundler # a Ruby library
# Rule of thumb: apt/dnf/pacman/brew install PROGRAMS for the system;
# pip/npm/gem install CODE LIBRARIES for a project. Never 'sudo pip'.🎯 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 — finish the two Ubuntu commands.
# 1) First refresh the package index so you have the latest lists.
sudo apt ______ git # 👉 replace ______ with update
# (this refreshes the lists; it does NOT install anything)
# 2) Now install the 'curl' package and its dependencies.
sudo apt ______ curl # 👉 replace ______ with install
# ✅ After step 2, 'curl' (and anything it needs) is installed.🎯 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 |
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.
# 🎯 MINI-CHALLENGE: a "fresh machine setup" cheat-sheet
#
# Imagine you just got a new computer and want to install three tools:
# git, curl, and htop. Write the commands for THREE platforms.
#
# 1. Ubuntu/Debian: refresh the lists, then install all three with apt.
# (Hint: you can list packages together: sudo apt install git curl htop)
# 2. Arch Linux: install the same three with pacman in one command.
# (Hint: sudo pacman -S git curl htop)
# 3. macOS: install the same three with Homebrew — remember, NO sudo.
#
# Then add a comment explaining WHY the macOS line has no sudo but the
# Ubuntu and Arch lines do.
#
# ✅ Example first line: sudo apt update && sudo apt install git curl htop
# your commands here🎉 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
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 — Connect to servers, generate key pairs with ssh-keygen, and copy files with scp
- Quick reference: Command Line cheat sheet
Frequently asked questions
What exactly is a 'package' and a 'dependency'?
A package is a bundle of software plus metadata (its name, version, and a list of what it needs). A dependency is another package that the first one requires in order to work. The package manager reads that metadata and automatically installs the dependencies for you, pulling everything from configured repositories (online collections of packages).
Does 'apt update' install my updates? It does not seem to.
Correct — apt update only refreshes the local index, the lists of which packages and versions are available. To actually install the newer versions of things you already have, run sudo apt upgrade. The usual pattern is two commands: sudo apt update, then sudo apt upgrade.
Why do apt, dnf, and pacman need sudo but Homebrew does not?
System package managers write into system-wide directories (like /usr) that only the root user may change, so they need sudo. Homebrew deliberately installs into its own prefix (such as /opt/homebrew or /usr/local) that your normal user owns, so it runs without sudo. Using sudo with brew can actually corrupt those permissions.
How are pip and npm different from apt or brew?
apt, dnf, pacman, and brew are SYSTEM package managers: they install programs for the whole machine. pip (Python), npm (Node), and gem (Ruby) are LANGUAGE/PROJECT managers: they install code libraries for a single language, usually per-project or per-user. They are not system managers and generally should not be run with sudo.
I am on a different distro — how do I know which manager to use?
Match it to the family: Debian and Ubuntu (and Mint) use apt; Fedora, RHEL, CentOS, and Rocky use dnf (older: yum); Arch and Manjaro use pacman; openSUSE uses zypper; and macOS commonly uses Homebrew. The verbs are similar everywhere — install, remove, update/upgrade, search — only the command name and flags change.