pacman Command Examples in Linux (Cheat Sheet)

“pacman” is the package manager for Arch Linux and its derivatives. It is used to install, remove, upgrade, and manage packages on the system.

Pacman uses a simple and straightforward command-line interface, and supports multiple repository sources, including the official Arch Linux repository and any additional repositories the user has added. It also supports transactions, ensuring that packages are installed and removed in a consistent and reliable manner.

Here are some common examples of how “pacman” can be used:

pacman Command Examples

1. Synchronize and update all packages:

# sudo pacman -Syu

2. Install a new package:

# sudo pacman -S package_name

3. Remove a package and its dependencies:

# sudo pacman -Rs package_name

4. Search the package database for a regular expression or keyword:

# pacman -Ss "search_pattern"

5. List installed packages and versions:

# pacman -Q

6. List only the explicitly installed packages and versions:

# pacman -Qe

7. List orphan packages (installed as dependencies but not actually required by any package):

# pacman -Qtdq

8. Empty the entire pacman cache:

# sudo pacman -Scc

pacman –upgrade Command Examples

1. Install one or more packages from files:

# sudo pacman --upgrade {{path/to/package1.pkg.tar.zst}}{{path/to/package2.pkg.tar.zst}}

2. Install a package without prompting:

# sudo pacman --upgrade --noconfirm {{path/to/package.pkg.tar.zst}}

3. Overwrite conflicting files during a package installation:

# sudo pacman --upgrade --overwrite {{path/to/file}} {{path/to/package.pkg.tar.zst}}

4. Install a package, skipping the dependency version checks:

# sudo pacman --upgrade --nodeps {{path/to/package.pkg.tar.zst}}

5. List packages that would be affected (does not install any packages):

# pacman --upgrade --print {{path/to/package.pkg.tar.zst}}

6. Display help:

# pacman --upgrade --help

pacman –sync Command Examples

1. Install a new package:

# sudo pacman --sync {{package_name}}

2. Synchronize and update all packages (add –downloadonly to download the packages and not update them):

# sudo pacman --sync --refresh --sysupgrade

3. Update all packages and install a new one without prompting:

# sudo pacman --sync --refresh --sysupgrade --noconfirm {{package_name}}

4. Search the package database for a regular expression or keyword:

# pacman --sync --search "{{search_pattern}}"

5. Display information about a package:

# pacman --sync --info {{package_name}}

6. Overwrite conflicting files during a package update:

# sudo pacman --sync --refresh --sysupgrade --overwrite {{path/to/file}}

7. Synchronize and update all packages, but ignore a specific package (can be used more than once):

# sudo pacman --sync --refresh --sysupgrade --ignore {{package_name}}

8. Remove not installed packages and unused repositories from the cache (use two –clean flags to clean all packages):

# sudo pacman --sync --clean

pacman –remove Command Examples

1. Remove a package and its dependencies:

# sudo pacman --remove --recursive {{package_name}}

2. Remove a package and both its dependencies and configuration files:

# sudo pacman --remove --recursive --nosave {{package_name}}

3. Remove a package without prompting:

# sudo pacman --remove --noconfirm {{package_name}}

4. Remove orphan packages (installed as dependencies but not required by any package):

# sudo pacman --remove --recursive --nosave $(pacman --query --unrequired --deps --quiet)

5. Remove a package and all packages that depend on it:

# sudo pacman --remove --cascade {{package_name}}

6. List packages that would be affected (does not remove any packages):

# pacman --remove --print {{package_name}}

7. Display help for this subcommand:

# pacman --remove --help

pacman –query Command Examples

1. List installed packages and versions:

# pacman --query

2. List only packages and versions that were explicitly installed:

# pacman --query --explicit

3. Find which package owns a file:

# pacman --query --owns {{filename}}

4. Display information about an installed package:

# pacman --query --info {{package_name}}

5. List files owned by a package:

# pacman --query --list {{package_name}}

6. List orphan packages (installed as dependencies but not required by any package):

# pacman --query --unrequired --deps --quiet

7. List installed packages not found in the repositories:

# pacman --query --foreign

8. List outdated packages:

# pacman --query --upgrades

pacman-mirrors Command Examples

1. Generate a mirrorlist using the default settings:

# sudo pacman-mirrors --fasttrack

2. Get the status of the current mirrors:

# pacman-mirrors --status

3. Display the current branch:

# pacman-mirrors --get-branch

4. Switch to a different branch:

# sudo pacman-mirrors --api --set-branch {{stable|unstable|testing}}

5. Generate a mirrorlist, only using mirrors in your country:

# sudo pacman-mirrors --geoip

pacman-key Command Examples

1. Initialize the pacman keyring:

# sudo pacman-key --init

2. Add the default Arch Linux keys:

# sudo pacman-key --populate archlinux

3. List keys from the public keyring:

# pacman-key --list-keys

4. Add the specified keys:

# sudo pacman-key --add path/to/keyfile.gpg

5. Receive a key from a key server:

# sudo pacman-key --recv-keys "uid|name|email"

6. Print the fingerprint of a specific key:

# pacman-key --finger "uid|name|email"

7. Sign an imported key locally:

# sudo pacman-key --lsign-key "uid|name|email"

8. Remove a specific key:

# sudo pacman-key --delete "uid|name|email"

pacman –files Command Examples

1. Update the package database:

# sudo pacman --files --refresh

2. Find the package that owns a specific file:

# pacman --files {{filename}}

3. Find the package that owns a specific file, using a regular expression:

# pacman --files --regex '{{regular_expression}}'

4. List only the package names:

# pacman --files --quiet {{filename}}

5. List the files owned by a specific package:

# pacman --files --list {{package_name}}

6. List only the absolute path to the files:

# pacman --query --list --quiet {{package_name}}

7. Display help:

# pacman --files --help

pacman –deptest Command Examples

1. Print the package names of the dependencies that aren’t installed:

# pacman --deptest {{package_name1}} {{package_name2}}

2. Check if the installed package satisfies the given minimum version:

# pacman --deptest "{{bash>=5}}"

3. Check if a later version of a package is installed:

# pacman --deptest "{{bash>5}}"

4. Display help:

# pacman --deptest --help

pacman –database Command Examples

1. Mark a package as implicitly installed:

# sudo pacman --database --asdeps {{package_name}}

2. Mark a package as explicitly installed:

# sudo pacman --database --asexplicit {{package_name}}

3. Check that all the package dependencies are installed:

# pacman --database --check

4. Check the repositories to ensure all specified dependencies are available:

# pacman --database --check --check

5. Display only error messages:

# pacman --database --check --quiet

6. Display help:

# pacman --database --help

Summary

In summary, “pacman” is a powerful and flexible package manager for Arch Linux and its derivatives, providing a simple and efficient way to install, remove, upgrade, and manage packages on the system.

Related Post