Kahibaro
Discord Login Register

Pacman (Arch Linux)

Understanding Pacman on Arch-Based Systems

pacman is the package manager used on Arch Linux and most Arch-based distributions (Manjaro, EndeavourOS, etc.). This chapter focuses on basic, everyday usage for beginners on an Arch-like system, not on advanced packaging or repository management.

Throughout, you’ll typically run pacman with sudo on a regular desktop system.

Basic Syntax and Important Options

The general format:

pacman uses short, combined options a lot. For example:

You’ll see the following flags frequently:

Updating Package Databases and the System

On Arch, updating is done with pacman directly (there’s no separate “distribution upgrade” command).

Refreshing the Package Databases

To refresh the list of available packages:

sudo pacman -Sy

This updates the databases but does not upgrade installed packages.

Full System Upgrade

On Arch, the normal way to update is a full system upgrade:

sudo pacman -Syu

This command:

On Arch, partial upgrades (updating only some packages) are discouraged; -Syu should be run to keep the system consistent.

Searching for Packages

To search in the official repositories:

pacman -Ss keyword

Examples:

To search locally installed packages:

pacman -Qs keyword

For example:

Installing Packages

To install a package from the official repositories:

sudo pacman -S package_name

Examples:

To install multiple packages at once:

sudo pacman -S package1 package2 package3

If packages are provided by different repositories, pacman chooses the one with the highest priority according to your pacman.conf (already set up on most systems).

Reinstalling Packages

If you need to reinstall a package that’s already installed:

sudo pacman -S package_name

pacman will detect that it is already installed and ask whether to reinstall.

You can also force a reinstall:

sudo pacman -S package_name --needed

--needed tells pacman not to reinstall if the latest version is already installed.

Removing Packages

To remove a package, but keep its dependencies (if other things use them):

sudo pacman -R package_name

To remove a package and dependencies that are no longer needed (i.e., installed as dependencies and not required by anything else):

sudo pacman -Rs package_name

The -s here stands for “recursive removal of unused dependencies” (but pacman will show you what it’s going to remove and ask for confirmation).

To remove a package and its configuration files in /etc (back up if needed!) you might use:

sudo pacman -Rns package_name

Flags:

Be cautious with -Rns on critical packages; always read the list of packages to be removed.

Querying Installed Packages

Some common queries:

List All Installed Packages

pacman -Q

This can be long; you can pipe it to tools like less or grep:

pacman -Q | less
pacman -Q | grep firefox

Check if a Package Is Installed

pacman -Q package_name

If the package is not installed, you’ll get an error.

Get Information About an Installed Package

pacman -Qi package_name

This shows version, install date, description, dependencies, etc.

Get Information About a Package in the Repositories

Even if not installed:

pacman -Si package_name

This shows what you would be installing, including repository, size, and dependencies.

List Files Installed by a Package

Useful for finding where something was installed:

pacman -Ql package_name

Find Which Package Owns a File

For a file already on your system:

pacman -Qo /path/to/file

For example:

pacman -Qo /usr/bin/ssh

This tells you which installed package provided that file.

Handling the Package Cache

pacman stores downloaded package files in a cache, usually /var/cache/pacman/pkg/. Over time, this can grow large.

View Cache Location

It’s defined in /etc/pacman.conf under the CacheDir configuration, typically:

CacheDir    = /var/cache/pacman/pkg/

Cleaning the Cache

To remove unused packages from the cache, leaving only the most recent versions of installed packages:

sudo pacman -Sc

To remove all cached packages (more aggressive):

sudo pacman -Scc

Use -Scc carefully; it removes everything, so you will need to re-download packages if you downgrade or reinstall.

Installing Local Package Files with pacman -U

Sometimes you have a package file (.pkg.tar.zst or similar) on your system, for example:

To install it:

sudo pacman -U /path/to/package.pkg.tar.zst

-U means “upgrade or install from a file”. pacman still resolves dependencies from repositories where possible.

This is different from the Arch User Repository (AUR) helpers, which are separate tools; pacman itself only works with official repositories and local package files.

Working with Orphans and Explicitly Installed Packages

On Arch, packages can be:

List Explicitly Installed Packages

pacman -Qe

This shows packages you explicitly installed (or that came as part of base groups).

List Orphaned Packages

“Orphans” are packages installed as dependencies that are no longer required by any installed package.

pacman -Qdt

You can remove orphans with:

sudo pacman -Rns $(pacman -Qdtq)

Here:

Always check the list before confirming removal.

Handling Common pacman Issues (Beginner-Level)

You will often see:

“Database Is Locked”

If you see something like:

error: failed to init transaction (unable to lock database)
  if you're sure a package manager is not already running, remove /var/lib/pacman/db.lck

Usually, this means another pacman instance or a GUI updater is running.

Steps:

  1. Check if pacman is running:
   ps aux | grep pacman
  1. If nothing is running and you are sure an update is not in progress, you can remove the lock:
   sudo rm /var/lib/pacman/db.lck

Then rerun your pacman command.

Conflicting Files

Sometimes you see:

error: failed to commit transaction (conflicting files)
file /path/file already exists in filesystem

This usually means a file from the new package would overwrite an existing file. As a beginner, the safest steps are:

  1. Read the error carefully to identify the file.
  2. Search online with the error message and package name.
  3. Only remove or move files if a trusted solution suggests it.

Avoid forcing overwrites with options you don’t fully understand (--overwrite), unless guided by reliable documentation.

pacman Configuration (Light Overview)

The main configuration file is /etc/pacman.conf. As a beginner, you normally don’t need to edit it except for:

Any changes should be made with care and usually only by following official or well-reviewed documentation.

Summary of Common pacman Commands

For quick reference:

These commands cover the daily pacman tasks you’ll need on Arch and Arch-based systems.

Views: 23

Comments

Please login to add a comment.

Don't have an account? Register now!