Cyberithub

16 Pacman Command Examples to Manage Packages on Arch Linux

Advertisements

In this article, I will take you through 16 Pacman command examples to manage packages on Arch Linux. pacman is a free and open source package manager for Linux systems. It is just like apt or apt-get package manager on Ubuntu/Debian systems and yum or dnf package manager on RHEL/CentOS systems. It is by default available in Arch Linux but it can be easily installed on other Linux flavors as well.

Unlike other packages, pacman package format is a zipped tar format. pacman provides some of the important features such as dependency support, package groups, install and uninstall scripts, and the ability to sync your local machine with a remote repository to automatically upgrade packages. More on official website.

16 Pacman Command Examples to Manage Packages on Arch Linux

16 Pacman Command Examples to Manage Packages on Arch Linux

Also Read: How to Install Yarn on Ubuntu 20.04 LTS (Focal Fossa)

Example 1: How to Check Pacman command version

To check the currently installed pacman version, you need to use pacman --version command as shown below.

[root@b8b4f6891acb /]# pacman --version

 .--. Pacman v6.0.1 - libalpm v13.0.1
/ _.-' .-. .-. .-. Copyright (C) 2006-2021 Pacman Development Team
\ '-.  '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet
 '--'
                   This program may be freely redistributed under
                   the terms of the GNU General Public License.

 

Example 2: How to Update System using pacman command

If you want to update and upgrade all the system packages to the latest one then you need to run pacman -Syu command as shown below.

[root@b8b4f6891acb /]# pacman -Syu
:: Synchronizing package databases...
core downloading...
extra downloading...
community downloading...
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Package (3)   Old Version New Version Net Change Download Size

core/gcc-libs 12.1.0-1    12.1.0-2    -0.01 MiB  28.03 MiB
core/gnutls   3.7.4-3     3.7.5-1      0.04 MiB  2.77 MiB
core/libldap  2.6.1-1     2.6.2-1      0.00 MiB  0.27 MiB

Total Download Size: 31.07 MiB
Total Installed Size: 116.14 MiB
Net Upgrade Size: 0.04 MiB

:: Proceed with installation? [Y/n] Y
.....................................................

-S : synchronize packages from the remote repo.

-y : download fresh package databases from the server.

-u : upgrade installed packages.

 

Example 3: How to Install a Package using pacman command

To install a new package in the System, you need to use pacman -S <package_name> syntax. In this example, we are installing telegram-desktop package by using pacman -S telegram-desktop command as shown below.

[root@b8b4f6891acb /]# pacman -S telegram-desktop
resolving dependencies...
:: There are 2 providers available for jack:
:: Repository extra
1) jack2 2) pipewire-jack

Enter a number (default=1):
looking for conflicting packages...
warning: dependency cycle detected:
warning: harfbuzz will be installed before its freetype2 dependency
warning: dependency cycle detected:
warning: mesa will be installed before its libglvnd dependency

Package (168)            New Version   Net Change  Download Size

community/abseil-cpp     20211102.0-2  4.93 MiB    0.91 MiB
extra/alsa-card-profiles 1:0.3.51-1    0.17 MiB    0.03 MiB
extra/alsa-lib           1.2.6.1-1     1.63 MiB    0.46 MiB
extra/alsa-topology-conf 1.2.5.1-1     0.33 MiB    0.01 MiB
...................................................

 

Example 4: How to remove a Package using pacman command

If you want to simply remove the package from your System then you need to use -R switch with pacman command. For example, here we are removing telegram-desktop package by using pacman -R telegram-desktop command as shown below.

[root@b8b4f6891acb /]# pacman -R telegram-desktop
checking dependencies...

Package (1)      Old Version Net Change

telegram-desktop 3.7.3-1     -71.93 MiB

Total Removed Size: 71.93 MiB

:: Do you want to remove these packages? [Y/n] Y
:: Processing package changes...
removing telegram-desktop...
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...

If you want to remove the package along with all its dependencies that are not needed by any other application then you need to use -Rs switch with pacman command as shown below.

[root@b8b4f6891acb /]# pacman -Rs telegram-desktop
checking dependencies...
:: iproute2 optionally requires db: userspace arp daemon
warning: dependency cycle detected:
warning: harfbuzz will be removed after its freetype2 dependency
warning: dependency cycle detected:
warning: mesa will be removed after its libglvnd dependency

Package (168)      Old Version   Net Change

abseil-cpp         20211102.0-2  -4.93 MiB
alsa-card-profiles 1:0.3.51-1    -0.17 MiB
alsa-lib           1.2.6.1-1     -1.63 MiB
alsa-topology-conf 1.2.5.1-1     -0.33 MiB
alsa-ucm-conf      1.2.6.3-1     -0.20 MiB
..............................................

If you want to properly remove the package by avoiding the orphan dependencies and erasing the global configuration then use -Rns switch with pacman command as shown below.

[root@b8b4f6891acb /]# pacman -Rns telegram-desktop
checking dependencies...
:: iproute2 optionally requires db: userspace arp daemon
warning: dependency cycle detected:
warning: harfbuzz will be removed after its freetype2 dependency
warning: dependency cycle detected:
warning: mesa will be removed after its libglvnd dependency

Package (168)      Old Version   Net Change

abseil-cpp         20211102.0-2  -4.93 MiB
alsa-card-profiles 1:0.3.51-1    -0.17 MiB
alsa-lib           1.2.6.1-1     -1.63 MiB
................................................

 

Example 5: How to Check Info about an Installed Package

If you want to query complete information about an installed package then you need to use pacman -Qi <package_name> syntax. In this example, we are looking for complete information about telegram-desktop package using pacman -Qi telegram-desktop command as shown below.

[root@b8b4f6891acb /]# pacman -Qi telegram-desktop
Name : telegram-desktop
Version : 3.7.3-1
Description : Official Telegram Desktop client
Architecture : x86_64
URL : https://desktop.telegram.org/
Licenses : GPL3
Groups : None
Provides : None
Depends On : hunspell ffmpeg4.4 hicolor-icon-theme lz4 minizip openal ttf-opensans qt6-imageformats qt6-svg qt6-wayland qt6-5compat xxhash
glibmm rnnoise pipewire libxtst libxrandr jemalloc abseil-cpp libdispatch
Optional Deps : webkit2gtk: embedded browser features
xdg-desktop-portal: desktop integration
Required By : None
Optional For : None
Conflicts With : None
Replaces : None
Installed Size : 71.93 MiB
Packager : Sven-Hendrik Haase <svenstaro@gmail.com>
Build Date : Wed 27 Apr 2022 11:48:43 PM UTC
Install Date : Fri 20 May 2022 02:52:53 PM UTC
Install Reason : Explicitly installed
Install Script : No
Validated By : Signature

-Q : query the package database.

-i : view package information.

 

Example 6: How to Query repo about a package

If you want to check the availability of a package in default repo then you need to use -Ss switch with pacman command. In this example, we are checking the availability of telegram-desktop package by using pacman -Ss telegram-desktop command as shown below.

[root@b8b4f6891acb /]# pacman -Ss telegram-desktop
community/telegram-desktop 3.7.3-1
Official Telegram Desktop client

 

Example 7: How to Check all the Installed Packages not available in Official Repo

If you want to check all the packages installed in your system which are not from the official repo then you need to use pacman -Qm command as shown below.

[root@b8b4f6891acb /]# pacman -Qm

 

Example 8: How to test local database for validity using pacman command

If you want to test your local database for validity then you need to use pacman -Dkv command as shown below.

[root@b8b4f6891acb /]# pacman -Dkv
Root : /
Conf File : /etc/pacman.conf
DB Path : /var/lib/pacman/
Cache Dirs: /var/cache/pacman/pkg/
Hook Dirs : /usr/share/libalpm/hooks/ /etc/pacman.d/hooks/
Lock File : /var/lib/pacman/db.lck
Log File : /var/log/pacman.log
GPG Dir : /etc/pacman.d/gnupg/
Targets : None
No database errors have been found!

 

Example 9: How to List all the files owned by a Package

To list all the files installed by a package, you can use -Ql switch with pacman command. In this example, we are checking all the files owned by telegram-desktop package by using pacman -Ql telegram-desktop command as shown below. This is equivalent to dpkg -L command on Ubuntu/Debian based systems.

[root@b8b4f6891acb /]# pacman -Ql telegram-desktop
telegram-desktop /usr/
telegram-desktop /usr/bin/
telegram-desktop /usr/bin/telegram-desktop
telegram-desktop /usr/share/
telegram-desktop /usr/share/applications/
telegram-desktop /usr/share/applications/telegramdesktop.desktop
telegram-desktop /usr/share/icons/
telegram-desktop /usr/share/icons/hicolor/
telegram-desktop /usr/share/icons/hicolor/128x128/
telegram-desktop /usr/share/icons/hicolor/128x128/apps/
telegram-desktop /usr/share/icons/hicolor/128x128/apps/telegram.png
telegram-desktop /usr/share/icons/hicolor/16x16/
telegram-desktop /usr/share/icons/hicolor/16x16/apps/
telegram-desktop /usr/share/icons/hicolor/16x16/apps/telegram.png
telegram-desktop /usr/share/icons/hicolor/256x256/
telegram-desktop /usr/share/icons/hicolor/256x256/apps/
telegram-desktop /usr/share/icons/hicolor/256x256/apps/telegram.png
telegram-desktop /usr/share/icons/hicolor/32x32/
telegram-desktop /usr/share/icons/hicolor/32x32/apps/
telegram-desktop /usr/share/icons/hicolor/32x32/apps/telegram.png
telegram-desktop /usr/share/icons/hicolor/48x48/
telegram-desktop /usr/share/icons/hicolor/48x48/apps/
telegram-desktop /usr/share/icons/hicolor/48x48/apps/telegram.png
telegram-desktop /usr/share/icons/hicolor/512x512/
telegram-desktop /usr/share/icons/hicolor/512x512/apps/
telegram-desktop /usr/share/icons/hicolor/512x512/apps/telegram.png
telegram-desktop /usr/share/icons/hicolor/64x64/
telegram-desktop /usr/share/icons/hicolor/64x64/apps/
telegram-desktop /usr/share/icons/hicolor/64x64/apps/telegram.png
telegram-desktop /usr/share/metainfo/
telegram-desktop /usr/share/metainfo/telegramdesktop.metainfo.xml

 

Example 10: How to view all members of a Package Group

To check all the members of a package group, you need to use -Qg switch pacman command. In this example, we are checking all the members of qt6 group by using pacman -Qg qt6 command as shown below.

[root@b8b4f6891acb /]# pacman -Qg qt6
qt6 qt6-5compat
qt6 qt6-base
qt6 qt6-declarative
qt6 qt6-imageformats
qt6 qt6-svg
qt6 qt6-translations
qt6 qt6-wayland

 

Example 11: How to List all unneeded packages using pacman command

If you want to list all the orphan packages which are not needed by any application or any other packages then you need to use pacman -Qdt command as shown below.

[root@4ad461722fb8 /]# pacman -Qdt
abseil-cpp 20211102.0-2
ffmpeg4.4 4.4.1-5
glibmm 2.66.4-1
hunspell 1.7.0-3
jemalloc 1:5.2.1-6
libdispatch 5.5.0-1
libxtst 1.2.3-4
minizip 1:1.2.12-2
openal 1.22.0-1
qt6-5compat 6.3.0-2
qt6-imageformats 6.3.0-2
qt6-svg 6.3.0-1
rnnoise 0.4.1-1
ttf-opensans 1.101-2
xxhash 0.8.1-2

 

Example 12: How to Check the owner of a File using pacman command

If you want to check the owner of a file then you need to use -Qo switch with pacman command. In this example, we are checking the owner of binary file telegram-desktop by using pacman -Qo telegram-desktop command as shown below.

[root@4ad461722fb8 /]# pacman -Qo telegram-desktop
/usr/bin/telegram-desktop is owned by telegram-desktop 3.7.3-1

 

Example 13: How to Search keyword from Installed Packages

If you want to search for a specific keyword from all the installed packages then you need to use -Qs switch with pacman command. In this example, we are searching keyword telegram-desktop from Installed packages by using pacman -Qs telegram-desktop command as shown below.

[root@4ad461722fb8 /]# pacman -Qs telegram-desktop
local/telegram-desktop 3.7.3-1
Official Telegram Desktop client

 

Example 14: How to List all Explicitly Installed Packages

If you want to list all the explicitly installed packages then you need to use pacman -Qe command as shown below.

[root@4ad461722fb8 /]# pacman -Qe
base 2-2
telegram-desktop 3.7.3-1

 

Example 15: How to Check all the pacman operations

To check all the operations available with pacman command, you need to use pacman -h command as shown below.

[root@4ad461722fb8 /]# pacman -h
usage: pacman <operation> [...]
operations:
pacman {-h --help}
pacman {-V --version}
pacman {-D --database} <options> <package(s)>
pacman {-F --files} [options] [file(s)]
pacman {-Q --query} [options] [package(s)]
pacman {-R --remove} [options] <package(s)>
pacman {-S --sync} [options] [package(s)]
pacman {-T --deptest} [options] [package(s)]
pacman {-U --upgrade} [options] <file(s)>

use 'pacman {-h --help}' with an operation for available options

 

Example 16: How to Check all the options available for pacman operations

To check all the options available with a specific operation, you need to use -h switch with that operation. For example to check all the options available for query operation, you need to use pacman -Q -h command as shown below.

[root@4ad461722fb8 /]# pacman -Q -h
usage: pacman {-Q --query} [options] [package(s)]
options:
-b, --dbpath <path> set an alternate database location
-c, --changelog view the changelog of a package
-d, --deps list packages installed as dependencies [filter]
-e, --explicit list packages explicitly installed [filter]
-g, --groups view all members of a package group
-i, --info view package information (-ii for backup files)
-k, --check check that package files exist (-kk for file properties)
-l, --list list the files owned by the queried package

Leave a Comment