|

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 TypePurpose
Metadata files (YAML, JSON)Package info, dependencies, install instructions
Pre-install scriptsRun before installation
Post-install scriptsRun after installation
Programs / binariesThe actual software
Config filesDefault 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 ManagerFull NameDefault For
APTAdvanced Package ToolDebian, Ubuntu, Linux Mint
YUMYellowdog Updater ModifierRed Hat, Fedora
ZypperopenSUSE
pacmanArch 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:

  1. Downloads dependencies
  2. Extracts software
  3. Creates directories
  4. 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.

CommandDescription
apt updateUpdates the package index
apt upgradeUpgrades all installed packages on the system
apt list --upgradableShows the packages that can be upgraded
apt install nanoInstalls the nano package
apt remove nanoRemoves the nano package
apt purge nanoRemoves all package data including user configuration files
apt autoremoveRemoves cached packages and uninstalled dependencies
apt search nanoSearches 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.

CommandDescription
yum upgradeUpgrades all packages
yum install packageNameInstalls packageName
yum install /pathTo/file.rpmInstalls a local RPM package
yum reinstall packageNameReinstalls packageName
yum remove packageNameRemoves packageName, but not the configuration files
yum downgrade packageNameInstalls packageName’s previous version
yum search packageNameSearches 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.

CommandDescription
zypper upUpdates all packages
zypper in packageNameInstalls packageName
zypper in packageName.rpmInstalls a local RPM file
zypper re packageNameRemoves packageName
zypper se packageNameSearches for packageName
zypper source-install packageNameDownloads source code and installs it
zypper reposLists 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.

CommandDescription
pacman -SyuUpgrades all packages
pacman -S packageNameInstalls packageName
pacman -Rsc packageNameUninstalls packageName
pacman -Ss packageNameSearches for packageName
pacman -Qs packageNameSearches for installed packageName
pacman -QdtLists 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)

CommandPurpose
apt updateRefresh package index
apt upgradeUpgrade all packages
apt list --upgradableList upgradable packages
apt install PKGInstall package
apt remove PKGRemove package
apt purge PKGRemove package + config
apt autoremoveClean unused dependencies
apt search PKGSearch for package

YUM (Red Hat / Fedora)

CommandPurpose
yum upgradeUpgrade all packages
yum install PKGInstall package
yum install /path/file.rpmInstall local RPM
yum reinstall PKGReinstall package
yum remove PKGRemove package
yum downgrade PKGDowngrade package
yum search PKGSearch for package

Zypper (openSUSE)

CommandPurpose
zypper upUpdate all packages
zypper in PKGInstall package
zypper in PKG.rpmInstall local RPM
zypper re PKGRemove package
zypper se PKGSearch for package
zypper source-install PKGDownload + install source
zypper reposList repositories

pacman (Arch Linux)

CommandPurpose
pacman -SyuUpgrade all packages
pacman -S PKGInstall package
pacman -Rsc PKGUninstall package
pacman -Ss PKGSearch for package
pacman -Qs PKGSearch installed package
pacman -QdtList 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

PitfallProblemSolution
Forgot apt updatePackage not foundRun apt update first
Used remove instead of purgeConfig files remainUse apt purge
Partial upgrade on ArchSystem breaksAlways pacman -Syu
Orphaned packages pile upWasted disk spaceRun autoremove / -Qdt
Wrong package managerCommand not foundMatch to your distro
Ignoring dependenciesBroken installLet the manager handle it
No sudoPermission deniedPrefix 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

ManagerDistro FamilyInstallRemoveUpdateSearch
APTDebian/Ubuntuapt installapt remove / apt purgeapt upgradeapt search
YUMRed Hat/Fedorayum installyum removeyum upgradeyum search
ZypperopenSUSEzypper inzypper rezypper upzypper se
pacmanArchpacman -Spacman -Rscpacman -Syupacman -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 purge removes config files too, while apt remove keeps them
  • pacman -Qdt finds unneeded packages; pipe into pacman -Rns to 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!