Linux CLI 26 🐧 Package management
A package manager is a tool that automates installing, upgrading, configuring, and removing software. Each package manager maintains a list of software packages that can be installed, updated, and removed from the system. Package managers also provide tools to search for packages, install dependencies, manage configurations, and automate updates. Almost all packages can be found on the internet.
A package file is a collection of files that constitute a software package. Those files are:
| File Type | Purpose |
|---|---|
| Metadata files (YAML, JSON) | Package info, dependencies, install instructions |
| Pre-install scripts | Run before installation |
| Post-install scripts | Run after installation |
| Programs / binaries | The actual software |
| Config files | Default configuration |
Metadata files contain information about the package’s dependencies, installation instructions, version, author, etc.
Key point: The package manager reads the metadata to know what to install and how to configure it.
a – Package management introduction
Each package manager maintains a list of software packages that can be installed, updated, and removed from the system.
Package managers also provide tools to:
- Search for packages
- Install dependencies automatically
- Manage configurations
- Automate updates
Almost all packages can be found on the internet through repositories.
A package file is a collection of files that constitute a software package. Those files are metadata files (YAML, JSON), pre/post installation scripts, and numerous programs.
Metadata files contain information about the package’s dependencies, installation instructions, etc.
b – Common package managers
Common package managers:
| Package Manager | Full Name | Default For |
|---|---|---|
| APT | Advanced Package Tool | Debian, Ubuntu, Linux Mint |
| YUM | Yellowdog Updater Modifier | Red Hat, Fedora |
| Zypper | — | openSUSE |
| pacman | — | Arch Linux |
When you install a software package with one of the above package managers, the package manager reads the metadata files from the package to determine what packages need to be installed and how they should be configured.
It then:
- Downloads dependencies
- Extracts software
- Creates directories
- Sets up configurations
Example — installing a package with APT:
$ apt install nano
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
nano
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 281 kB of archives.
After this operation, 1,024 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 nano amd64 6.2-1 [281 kB]
Fetched 281 kB in 0s (1,204 kB/s)
Selecting previously unselected package nano.
(Reading database ... 154321 files and directories currently installed.)
Preparing to unpack .../nano_6.2-1_amd64.deb ...
Unpacking nano (6.2-1) ...
Setting up nano (6.2-1) ...
Processing triggers for man-db (2.10.2-1) ...
c – apt package manager
APT (Advanced Package Tool) is the default for Debian, Ubuntu, and Linux Mint.
| Command | Description |
|---|---|
apt update | Updates the package index |
apt upgrade | Upgrades all installed packages on the system |
apt list --upgradable | Shows the packages that can be upgraded |
apt install nano | Installs the nano package |
apt remove nano | Removes the nano package |
apt purge nano | Removes all package data including user configuration files |
apt autoremove | Removes cached packages and uninstalled dependencies |
apt search nano | Searches for a package named nano (regex supported) |
Examples:
# Update the package index
$ apt update
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
...
Reading package lists... Done
Building dependency tree... Done
# Upgrade all packages
$ apt upgrade
Reading package lists... Done
Building dependency tree... Done
Calculating upgrade... Done
The following packages will be upgraded:
curl git vim
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
...
# List upgradable packages
$ apt list --upgradable
Listing... Done
curl/jammy-updates 7.81.0-1ubuntu1.15 amd64 [upgradable from: 7.81.0-1ubuntu1.14]
git/jammy-updates 1:2.34.1-1ubuntu1.10 amd64 [upgradable from: 1:2.34.1-1ubuntu1.9]
vim/jammy-updates 2:8.2.3995-1ubuntu2.13 amd64 [upgradable from: 2:8.2.3995-1ubuntu2.12]
# Install a package
$ apt install nano
...
# Remove a package (keeps config)
$ apt remove nano
...
# Purge a package (removes config too)
$ apt purge nano
...
# Clean unused dependencies
$ apt autoremove
Reading package lists... Done
Building dependency tree... Done
The following packages will be REMOVED:
libcurl4 libgit2-1.1 ...
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
...
# Search for a package
$ apt search nano
Sorting... Done
Full Text Search... Done
nano/jammy 6.2-1 amd64
small, friendly text editor inspired by Pico
...
d – yum package manager
YUM (Yellowdog Updater Modifier) is the default for Red Hat and Fedora.
| Command | Description |
|---|---|
yum upgrade | Upgrades all packages |
yum install packageName | Installs packageName |
yum install /pathTo/file.rpm | Installs a local RPM package |
yum reinstall packageName | Reinstalls packageName |
yum remove packageName | Removes packageName, but not the configuration files |
yum downgrade packageName | Installs packageName’s previous version |
yum search packageName | Searches for packageName |
Examples:
# Upgrade all packages
$ yum upgrade
...
# Install a package
$ yum install nano
...
# Install a local RPM
$ yum install /home/kronos/downloads/nano-6.2-1.x86_64.rpm
...
# Reinstall
$ yum reinstall nano
...
# Remove (keeps config)
$ yum remove nano
...
# Downgrade
$ yum downgrade nano
...
# Search
$ yum search nano
...
e – zypper package manager
Zypper is the default for openSUSE.
| Command | Description |
|---|---|
zypper up | Updates all packages |
zypper in packageName | Installs packageName |
zypper in packageName.rpm | Installs a local RPM file |
zypper re packageName | Removes packageName |
zypper se packageName | Searches for packageName |
zypper source-install packageName | Downloads source code and installs it |
zypper repos | Lists all known repositories |
Examples:
# Update all packages
$ zypper up
...
# Install a package
$ zypper in nano
...
# Install a local RPM
$ zypper in ./nano-6.2-1.x86_64.rpm
...
# Remove
$ zypper re nano
...
# Search
$ zypper se nano
...
# Source install
$ zypper source-install nano
...
# List repositories
$ zypper repos
Repository priorities are without effect. All enabled repositories share the same priority.
# | Alias | Name | Enabled | GPG Check | Refresh
---+---------------------------+------------------------------------+---------+-----------+--------
1 | openSUSE-Leap-15.5-1 | openSUSE-Leap-15.5-1 | Yes | (r ) Yes | No
2 | repo-debug | Debug Repository | No | ---- | ----
...
f – pacman package manager
pacman is the default for Arch Linux.
| Command | Description |
|---|---|
pacman -Syu | Upgrades all packages |
pacman -S packageName | Installs packageName |
pacman -Rsc packageName | Uninstalls packageName |
pacman -Ss packageName | Searches for packageName |
pacman -Qs packageName | Searches for installed packageName |
pacman -Qdt | Lists unneeded packages |
pacman -Rns $(pacman -Qdtq) | Uninstalls unneeded packages |
Examples:
# Upgrade all packages
$ pacman -Syu
:: Synchronizing package databases...
core is up to date
extra is up to date
community is up to date
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...
...
# Install a package
$ pacman -S nano
resolving dependencies...
looking for conflicting packages...
Packages (1) nano-6.2-1
Total Installed Size: 0.82 MiB
...
# Uninstall (with dependencies and config)
$ pacman -Rsc nano
...
# Search for a package
$ pacman -Ss nano
extra/nano 6.2-1
Pico editor clone with enhancements
...
# Search for an installed package
$ pacman -Qs nano
local/nano 6.2-1
Pico editor clone with enhancements
# List unneeded packages (orphans)
$ pacman -Qdt
libfoo 1.2.3-1
libbar 4.5.6-1
# Remove unneeded packages
$ pacman -Rns $(pacman -Qdtq)
...
Complete Example Session
# ============================================
# PART 1: APT (DEBIAN / UBUNTU)
# ============================================
# Update package index
$ apt update
# Upgrade all packages
$ apt upgrade
# Check what can be upgraded
$ apt list --upgradable
# Install nano
$ apt install nano
# Verify installation
$ nano --version
GNU nano, version 6.2
# Remove nano (keeps config)
$ apt remove nano
# Purge nano (removes config too)
$ apt purge nano
# Clean unused dependencies
$ apt autoremove
# Search for a package
$ apt search nano
# ============================================
# PART 2: YUM (RED HAT / FEDORA)
# ============================================
$ yum upgrade
$ yum install nano
$ yum install /path/to/file.rpm
$ yum reinstall nano
$ yum remove nano
$ yum downgrade nano
$ yum search nano
# ============================================
# PART 3: ZYPPER (OPENSUSE)
# ============================================
$ zypper up
$ zypper in nano
$ zypper in ./nano.rpm
$ zypper re nano
$ zypper se nano
$ zypper source-install nano
$ zypper repos
# ============================================
# PART 4: PACMAN (ARCH)
# ============================================
$ pacman -Syu
$ pacman -S nano
$ pacman -Rsc nano
$ pacman -Ss nano
$ pacman -Qs nano
$ pacman -Qdt
$ pacman -Rns $(pacman -Qdtq)
Quick Reference
APT (Debian / Ubuntu)
| Command | Purpose |
|---|---|
apt update | Refresh package index |
apt upgrade | Upgrade all packages |
apt list --upgradable | List upgradable packages |
apt install PKG | Install package |
apt remove PKG | Remove package |
apt purge PKG | Remove package + config |
apt autoremove | Clean unused dependencies |
apt search PKG | Search for package |
YUM (Red Hat / Fedora)
| Command | Purpose |
|---|---|
yum upgrade | Upgrade all packages |
yum install PKG | Install package |
yum install /path/file.rpm | Install local RPM |
yum reinstall PKG | Reinstall package |
yum remove PKG | Remove package |
yum downgrade PKG | Downgrade package |
yum search PKG | Search for package |
Zypper (openSUSE)
| Command | Purpose |
|---|---|
zypper up | Update all packages |
zypper in PKG | Install package |
zypper in PKG.rpm | Install local RPM |
zypper re PKG | Remove package |
zypper se PKG | Search for package |
zypper source-install PKG | Download + install source |
zypper repos | List repositories |
pacman (Arch Linux)
| Command | Purpose |
|---|---|
pacman -Syu | Upgrade all packages |
pacman -S PKG | Install package |
pacman -Rsc PKG | Uninstall package |
pacman -Ss PKG | Search for package |
pacman -Qs PKG | Search installed package |
pacman -Qdt | List unneeded packages |
pacman -Rns $(pacman -Qdtq) | Remove unneeded packages |
Best Practices
✅ Do This:
# Always update index before installing
apt update && apt install nano # ✅
# Use apt autoremove to clean up
apt autoremove # ✅
# Search before installing
apt search nano # ✅
# Use purge when you want config gone
apt purge nano # ✅
# Check what will be upgraded
apt list --upgradable # ✅
# Remove orphans on Arch
pacman -Rns $(pacman -Qdtq) # ✅
❌ Don’t Do This:
# Don't install without updating index
apt install nano # ❌ may fail
# Don't use remove when you want config gone
apt remove nano # ❌ leaves config
# Don't run partial upgrades on Arch
pacman -Sy nano # ❌ can break system!
# Always use: pacman -Syu nano # ✅
# Don't ignore orphaned packages
# Run pacman -Qdt periodically # ✅
# Don't mix package managers
# Use only one per system # ✅
Common Pitfalls
| Pitfall | Problem | Solution |
|---|---|---|
Forgot apt update | Package not found | Run apt update first |
Used remove instead of purge | Config files remain | Use apt purge |
| Partial upgrade on Arch | System breaks | Always pacman -Syu |
| Orphaned packages pile up | Wasted disk space | Run autoremove / -Qdt |
| Wrong package manager | Command not found | Match to your distro |
| Ignoring dependencies | Broken install | Let the manager handle it |
No sudo | Permission denied | Prefix with sudo |
Real-World Examples
1. Install a Web Server (APT)
$ apt update
$ apt install nginx
$ systemctl start nginx
$ systemctl enable nginx
2. Install Development Tools (APT)
$ apt update
$ apt install build-essential git curl vim
3. Remove a Package Completely (APT)
$ apt purge nginx
$ apt autoremove
4. Install a Local RPM (YUM)
$ yum install /home/kronos/downloads/google-chrome-stable.rpm
5. Search and Install (Zypper)
$ zypper se nano
$ zypper in nano
6. Full System Upgrade (pacman)
$ pacman -Syu
7. Clean Orphans (pacman)
$ pacman -Qdt
$ pacman -Rns $(pacman -Qdtq)
8. Find Which Package Owns a File
# Debian/Ubuntu
$ dpkg -S /usr/bin/nano
# Red Hat/Fedora
$ rpm -qf /usr/bin/nano
# Arch
$ pacman -Qo /usr/bin/nano
Visual: How a Package Manager Works
┌──────────────────────────────────────────────┐
│ You: apt install nano │
└─────────────────┬────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Package Manager (APT) │
│ │
│ 1. Reads package index │
│ 2. Resolves dependencies │
│ 3. Downloads .deb from repository │
│ 4. Runs pre-install scripts │
│ 5. Extracts files │
│ 6. Runs post-install scripts │
│ 7. Updates package database │
└─────────────────┬────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ nano is installed ✅ │
└──────────────────────────────────────────────┘
Summary
| Manager | Distro Family | Install | Remove | Update | Search |
|---|---|---|---|---|---|
| APT | Debian/Ubuntu | apt install | apt remove / apt purge | apt upgrade | apt search |
| YUM | Red Hat/Fedora | yum install | yum remove | yum upgrade | yum search |
| Zypper | openSUSE | zypper in | zypper re | zypper up | zypper se |
| pacman | Arch | pacman -S | pacman -Rsc | pacman -Syu | pacman -Ss |
Key takeaways:
- A package manager installs, updates, removes, and searches for software
- A package file contains metadata, scripts, and programs
- APT is used on Debian/Ubuntu, YUM on Red Hat/Fedora, Zypper on openSUSE, pacman on Arch
- The package manager reads metadata to resolve dependencies and configure software
- Commands differ by manager but follow the same pattern: install, remove, update, search
apt purgeremoves config files too, whileapt removekeeps thempacman -Qdtfinds unneeded packages; pipe intopacman -Rnsto remove them- Never do partial upgrades on Arch — always use
pacman -Syu
Remember: Package managers are the backbone of software management on Linux. Learn the one for your distro — APT for Debian-based, YUM for Red Hat-based, Zypper for openSUSE, pacman for Arch. The concepts are the same everywhere: install, remove, update, search. Know the differences: apt purge vs apt remove, yum remove vs yum downgrade, pacman -S vs pacman -Rsc. Master your package manager and you control your system.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!