Files
MajorWiki/01-linux/packages/package-management-reference.md
MajorLinux 6592eb4fea wiki: audit fixes — broken links, wikilinks, frontmatter, stale content (66 files)
- Fixed 4 broken markdown links (bad relative paths in See Also sections)
- Corrected n8n port binding to 127.0.0.1:5678 (matches actual deployment)
- Updated SnapRAID article with actual majorhome paths (/majorRAID, disk1-3)
- Converted 67 Obsidian wikilinks to relative markdown links or plain text
- Added YAML frontmatter to 35 articles missing it entirely
- Completed frontmatter on 8 articles with missing fields

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 11:16:29 -04:00

173 lines
4.9 KiB
Markdown

---
title: "Linux Package Management Reference: apt, dnf, pacman"
domain: linux
category: packages
tags: [packages, apt, dnf, pacman, linux, distros]
status: published
created: 2026-03-08
updated: 2026-03-08
---
# Linux Package Management Reference: apt, dnf, pacman
Every major Linux distro has a package manager. The commands are different but the concepts are the same: install, remove, update, search. Here's the equivalent commands across the three you're most likely to encounter.
## Common Tasks by Package Manager
| Task | apt (Debian/Ubuntu) | dnf (Fedora/RHEL) | pacman (Arch) |
|---|---|---|---|
| Update package index | `apt update` | `dnf check-update` | `pacman -Sy` |
| Upgrade all packages | `apt upgrade` | `dnf upgrade` | `pacman -Su` |
| Update index + upgrade | `apt update && apt upgrade` | `dnf upgrade` | `pacman -Syu` |
| Install a package | `apt install pkg` | `dnf install pkg` | `pacman -S pkg` |
| Remove a package | `apt remove pkg` | `dnf remove pkg` | `pacman -R pkg` |
| Remove + config files | `apt purge pkg` | `dnf remove pkg` | `pacman -Rn pkg` |
| Search for a package | `apt search term` | `dnf search term` | `pacman -Ss term` |
| Show package info | `apt show pkg` | `dnf info pkg` | `pacman -Si pkg` |
| List installed | `apt list --installed` | `dnf list installed` | `pacman -Q` |
| Which pkg owns file | `dpkg -S /path/to/file` | `rpm -qf /path/to/file` | `pacman -Qo /path/to/file` |
| List files in pkg | `dpkg -L pkg` | `rpm -ql pkg` | `pacman -Ql pkg` |
| Clean cache | `apt clean` | `dnf clean all` | `pacman -Sc` |
## apt (Debian, Ubuntu, and derivatives)
```bash
# Always update before installing
sudo apt update
# Install
sudo apt install nginx
# Install multiple
sudo apt install nginx curl git
# Remove
sudo apt remove nginx
# Remove with config files
sudo apt purge nginx
# Autoremove orphaned dependencies
sudo apt autoremove
# Search
apt search nginx
# Show package details
apt show nginx
# Upgrade a specific package
sudo apt install --only-upgrade nginx
```
**APT sources** live in `/etc/apt/sources.list` and `/etc/apt/sources.list.d/`. Third-party PPAs go here. After adding a source, run `apt update` before installing from it.
## dnf (Fedora, RHEL, AlmaLinux, Rocky)
```bash
# Update everything
sudo dnf upgrade
# Install
sudo dnf install nginx
# Remove
sudo dnf remove nginx
# Search
dnf search nginx
# Info
dnf info nginx
# List groups (collections of packages)
dnf group list
# Install a group
sudo dnf group install "Development Tools"
# History — see what was installed and when
dnf history
dnf history info <id>
# Undo a transaction
sudo dnf history undo <id>
```
dnf's history and undo features are underused and genuinely useful when you've installed something that broke things.
## pacman (Arch, Manjaro)
```bash
# Full system update (do this before anything else, Arch is rolling)
sudo pacman -Syu
# Install
sudo pacman -S nginx
# Remove
sudo pacman -R nginx
# Remove with dependencies not needed by anything else
sudo pacman -Rs nginx
# Search
pacman -Ss nginx
# Info
pacman -Si nginx
# Query installed packages
pacman -Q # all installed
pacman -Qs nginx # search installed
pacman -Qi nginx # info on installed package
# Find orphaned packages
pacman -Qdt
# Clean package cache
sudo pacman -Sc # keep installed versions
sudo pacman -Scc # remove all cached packages
```
**AUR (Arch User Repository)** — packages not in the official repos. Use an AUR helper like `yay` or `paru`:
```bash
# Install yay
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si
# Then use like pacman
yay -S package-name
```
## Flatpak and Snap (Distro-Agnostic)
For software that isn't in your distro's repos or when you want a sandboxed installation:
```bash
# Flatpak
flatpak install flathub com.spotify.Client
flatpak run com.spotify.Client
flatpak update
# Snap
sudo snap install spotify
sudo snap refresh
```
Flatpak is what I prefer — better sandboxing story, Flathub has most things you'd want. Snap works fine but the infrastructure is more centralized.
## Gotchas & Notes
- **Always `apt update` before `apt install`.** Installing from a stale index can grab outdated versions or fail entirely.
- **`apt upgrade` vs `apt full-upgrade`:** `full-upgrade` (or `dist-upgrade`) allows package removal to resolve conflicts. Use it for major upgrades. `upgrade` won't remove anything.
- **Arch is rolling — update frequently.** Partial upgrades on Arch cause breakage. Always do `pacman -Syu` (full update) before installing anything.
- **dnf is noticeably slower than apt on first run** due to metadata downloads. Gets faster after the cache is warm.
- **Don't mix package sources carelessly.** Adding random PPAs (apt) or COPR repos (dnf) can conflict with each other. Keep third-party sources to a minimum.
## See Also
- [linux-distro-guide-beginners](../distro-specific/linux-distro-guide-beginners.md)
- [linux-server-hardening-checklist](../../02-selfhosting/security/linux-server-hardening-checklist.md)