Pacman Command To Manage Packages On Arch Linux Based Systems

pacman stands for package manager utility (pacman). pacman is a command-line utility to install, build, remove and manage Arch Linux packages. pacman uses libalpm (Arch Linux Package Management (ALPM) library) as a back-end to perform all the actions. Some other package manger utilities which are being used widely in Linux are yum, dnf, apt-get, dpkg, rpm, Zypper, pacman, urpmi, etc.,

Now, i’m going to play on our Manjaro 15.10 box to explain and cover mostly used pacman commands with examples.

1) Common syntax/file location for pacman

See below for common syntax/ file location of pacman which will help you if you want to check more about it.

[General syntax for pacman]
pacman  [options] [targets]

[pacman config file location]
/etc/pacman.conf

[pacman cached file location]
/var/cache/pacman/pkg/

[pacman databases file location]
/var/lib/pacman/sync

[pacman history file location]
/var/log/pacman.log

2) Install a Package or packages

Use the below command to install any package or packages on your system. In this case i’m going to install apache & php.

[Install a single package]
# pacman -S apache

[Install more than one packages]
# pacman -S apache php

[Install a package forcefully]
# pacman -S --force apache

[Download a package without installation]
# pacman -Sw apache

[Install a local package]
# pacman -U /package_path

[Install a online (Remote Path) package]
# pacman -U http://xxxxxxx.com/xxxx.tar.xz

3) Remove a Package or packages

Use the below command to remove/erase any package or packages on your system. In this case I’m going to remove apache & php.

[Remove a single package]
# pacman -R apache

[Remove more than one packages]
# pacman -R apache php

[Remove a package along with its dependencies]
# pacman -Rs apache

[Removes targets that are not required by any other packages, use when removing a group]
# pacman -Ru gnome

4) update a Package or packages

Use the below command to update any package or packages on your system. In this case I’m going to update apache & php to latest version. If update available, it will upgrade the package to latest version otherwise reinstall current one.

[Upgrade a single package]
# pacman -Syu apache
:: Synchronizing package databases...
 core is up to date                                   0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 extra is up to date                                  0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 community is up to date                              0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 multilib is up to date                               0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
warning: apache-2.4.18-1 is up to date -- reinstalling
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (1) apache-2.4.18-1

Total Installed Size:  5.41 MiB
Net Upgrade Size:      0.00 MiB

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

[Upgrade more than one packages]
# pacman -Syu apache php

6) How to list packages

Use the below commands to list all the installed packages. It will take long time to listout better we can use more command to see page by page.

[To retrieve a list of the package installed]
# pacman -Q | more
a52dec 0.7.4-8
aalib 1.4rc5-11
accountsservice 0.6.40-1
acl 2.2.52-2
acpid 2.0.26-1
adwaita-icon-theme 3.18.0-1
alsa-firmware 1.0.29-1
alsa-lib 1.1.0-1
alsa-plugins 1.1.0-2
alsa-utils 1.1.0-1
apache 2.4.18-1

To retrieve a list of the files installed by a particular package.

# pacman -Ql apache
apache /etc/
apache /etc/httpd/
apache /etc/httpd/conf/
apache /etc/httpd/conf/extra/
apache /etc/httpd/conf/extra/httpd-autoindex.conf
apache /etc/httpd/conf/extra/httpd-dav.conf
apache /etc/httpd/conf/extra/httpd-default.conf
apache /etc/httpd/conf/extra/httpd-info.conf

7) Check updates

Use the below command to check available package updates on your system. If anything available it will perform the update.

# pacman -Syup
:: Synchronizing package databases...
 core is up to date                                   0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 extra is up to date                                  0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 community is up to date                              0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 multilib is up to date                               0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
:: Starting full system upgrade...

8) Search a package

If you don’t know the exact package name which you want to install, Use the search option it will return the matching string. In this case I’m going to search chromium.

[Search a package from database]
# pacman -Ss chromium
extra/chromium 48.0.2564.116-1
    The open-source project behind Google Chrome, an attempt at creating a safer, faster, and more stable browser
extra/qt5-webengine 5.5.1-9 (qt qt5)
    Provides support for web applications using the Chromium browser project
community/chromium-bsu 0.9.15.1-2
    A fast paced top scrolling shooter
community/chromium-chromevox latest-1
    Causes the Chromium web browser to automatically install and update the ChromeVox screen reader extention. Note: This
    package does not contain the extension code.
community/fcitx-mozc 2.17.2313.102-1
    Fcitx Module of A Japanese Input Method for Chromium OS, Windows, Mac and Linux (the Open Source Edition of Google Japanese
    Input)

You can Search already installed package by adding Q option with pacman.

# pacman -Qs apche
local/apache 2.4.18-1
    A high performance Unix-based HTTP server
local/apr 1.5.2-1
    The Apache Portable Runtime
local/apr-util 1.5.4-1
    The Apache Portable Runtime

[If you Search fresh package with Q option, you will not get any output]
# pacman -Qs chromium

9) Check package information

If you want to know the package detailed information before proceeding with the installation. Use the below command, it will give full information about the package like package version, size, repo name, etc..

[To get information about given package]
# pacman -Si chromium
Repository      : extra
Name            : chromium
Version         : 48.0.2564.116-1
Description     : The open-source project behind Google Chrome, an attempt at creating a safer, faster, and more stable browser
Architecture    : x86_64
URL             : http://www.chromium.org/
Licenses        : BSD
Groups          : None
Provides        : None
Depends On      : gtk2  nss  alsa-lib  xdg-utils  bzip2  libevent  libxss  icu  libexif  libgcrypt  ttf-font  systemd  dbus
                  flac  snappy  speech-dispatcher  pciutils  libpulse  harfbuzz  libsecret  libvpx  perl  perl-file-basedir
                  desktop-file-utils  hicolor-icon-theme
Optional Deps   : kdebase-kdialog: needed for file dialogs in KDE
                  gnome-keyring: for storing passwords in GNOME keyring
                  kwallet: for storing passwords in KWallet
Conflicts With  : None
Replaces        : None
Download Size   : 44.42 MiB
Installed Size  : 172.44 MiB
Packager        : Evangelos Foutras 
Build Date      : Fri 19 Feb 2016 04:17:12 AM IST
Validated By    : MD5 Sum  SHA-256 Sum  Signature

To get information about installed package

# pacman -Qi apache
Name            : apache
Version         : 2.4.18-1
Description     : A high performance Unix-based HTTP server
Architecture    : x86_64
URL             : http://www.apache.org/dist/httpd
Licenses        : APACHE
Groups          : None
Provides        : None
Depends On      : zlib  apr-util  pcre
Optional Deps   : lua: for mod_lua module [installed]
                  openssl: for mod_ssl module [installed]
                  libxml2: for mod_proxy_html, mod_xml2enc modules [installed]
                  nghttp2: for mod_http2 module
                  lynx: apachectl status
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 5.41 MiB
Packager        : Anatol Pomozov 
Build Date      : Mon 14 Dec 2015 09:36:34 PM IST
Install Date    : Thu 03 Mar 2016 12:52:34 PM IST
Install Reason  : Explicitly installed
Install Script  : Yes
Validated By    : Signature

[If you grep about fresh package with Q option, you will get below error message]
# pacman -Qi chromium
error: package 'chromium' was not found

Display the list of backup files and their modification states. If you installed apache 2.4.12 and later on stage, you upgraded to 2.4.18, it will shows modification states.

# pacman -Qii apache
Backup Files    :
UNMODIFIED	/etc/httpd/conf/httpd.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-autoindex.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-dav.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-default.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-info.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-languages.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-manual.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-mpm.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-multilang-errordoc.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-ssl.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-userdir.conf
UNMODIFIED	/etc/httpd/conf/extra/httpd-vhosts.conf
UNMODIFIED	/etc/httpd/conf/extra/proxy-html.conf
UNMODIFIED	/etc/httpd/conf/mime.types
UNMODIFIED	/etc/httpd/conf/magic
UNMODIFIED	/etc/logrotate.d/httpd

10) Install a package from particular Repository

Use the below command to Install a package from particular Repository. In this case I’m going to install mplayer package from Manjaro extra repository.

# pacman -S extra/mplayer

11) View package dependencies

Use the below command to View package dependencies.

# pactree apache
or
# pactree -c apache
or
# pactree -sc apache

apache
├─zlib
│ └─glibc
│   ├─linux-api-headers
│   ├─tzdata
│   └─filesystem
│     └─iana-etc
├─apr-util
│ ├─apr
│ │ └─util-linux
│ │   ├─pam
│ │   │ ├─glibc
│ │   │ ├─cracklib

To list all packages no longer required as dependencies.

$ pacman -Qdt
enca 1.18-1
farstream-0.1 0.1.2-5
gegl 0.3.4-5
gobject-introspection 1.46.0-1
lib32-curl 7.47.1-1
lib32-gconf 3.2.6-1
lib32-gperftools 2.4-1
lib32-libappindicator-gtk2 12.10.0-6
lib32-libcurl-gnutls 7.42.1-1

To list all packages explicitly installed and not required as dependencies

$ pacman -Qet
acpid 2.0.26-1
apache 2.4.18-1
autoconf 2.69-2
automake 1.15-1
b43-fwcutter 019-1
bison 3.0.4-1
blueman 2.0.3-1
catfish 1.3.4-2
corebird 1.1-1
cpupower 4.4-1
cronie 1.5.0-1
dmraid 1.0.0.rc16.3-10
ecryptfs-utils 108-2

12) Sync the database

Use the below commands to Sync the database. Do this before proceeding full system upgrade.

[Sync the database]
# pacman -Sy
:: Synchronizing package databases...
 core is up to date                                   0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 extra is up to date                                  0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 community is up to date                              0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 multilib is up to date                               0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%

Force Sync the database

# pacman -Syy
:: Synchronizing package databases...
 core                                               132.6 KiB  1524K/s 00:00 [############################################] 100%
 extra                                             1859.0 KiB   750K/s 00:02 [############################################] 100%
 community                                            3.5 MiB   149K/s 00:24 [############################################] 100%
 multilib                                           182.7 KiB  1363K/s 00:00 [############################################] 100%

13) Install Updates

Use the below commands to update entire system packages to latest version. Also we can upgrade our system to new version of Archi/Manjaro if its available.

[Update your system]
# pacman -Su
:: Starting full system upgrade...
 there is nothing to do

[Update your system & Sync the database]
# pacman -Syu
:: Synchronizing package databases...
 core is up to date                                   0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 extra is up to date                                  0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 community is up to date                              0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
 multilib is up to date                               0.0   B  0.00B/s 00:00 [--------------------------------------------]   0%
:: Starting full system upgrade...
 there is nothing to do

14) How to install group package

We can install group package, like if you want to install group of software in one shot. When you are installing group of packages, it will prompt you to select the packages from the group and you have option to exclude particular package or ranges of packages in the list.

[Install a group of packages]
# pacman -S gnome
:: There are 47 members in group gnome:
:: Repository extra
   1) adwaita-icon-theme  2) baobab  3) dconf-editor  4) empathy  5) eog  6) epiphany  7) evince  8) gdm  9) gnome-backgrounds
   10) gnome-calculator  11) gnome-contacts  12) gnome-control-center  13) gnome-desktop  14) gnome-dictionary
   15) gnome-disk-utility  16) gnome-font-viewer  17) gnome-keyring  18) gnome-screenshot  19) gnome-session
   20) gnome-settings-daemon  21) gnome-shell  22) gnome-shell-extensions  23) gnome-system-log  24) gnome-system-monitor
   25) gnome-terminal  26) gnome-themes-standard  27) gnome-user-docs  28) gnome-user-share  29) grilo-plugins  30) gucharmap
   31) gvfs  32) gvfs-afc  33) gvfs-goa  34) gvfs-google  35) gvfs-gphoto2  36) gvfs-mtp  37) gvfs-nfs  38) gvfs-smb
   39) mousetweaks  40) mutter  41) nautilus  42) sushi  43) totem  44) tracker  45) vino  46) xdg-user-dirs-gtk  47) yelp

[To Install all packages in the group, simply hit enter]
Enter a selection (default=all): 

[This will install 1 to 20 & 44 from the group]
Enter a selection (default=all): 1-20 44

[This will install all the packages from group except 25 to 30 & 38]
Enter a selection (default=all): ^25-30 ^38

To see what packages belong to the group

# pacman -Sg gnome
gnome adwaita-icon-theme
gnome baobab
gnome dconf-editor
gnome empathy
gnome eog
gnome epiphany
gnome evince
gnome gdm
gnome gnome-backgrounds
gnome gnome-calculator
gnome gnome-contacts

15) whatprovides function

This command searches which packages owns a file .

# pacman -Qo /etc/httpd/conf
/etc/httpd/conf/ is owned by apache 2.4.18-1

16) Clean pacman Cache

If we want to clean pacman package cache we can do it by firing below commands.

[remove all the cached packages which are not currently installed]
# pacman -Sc
Packages to keep:
  All locally installed packages

Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n] y
removing old packages from cache...

Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...

Empty cached packages.

# pacman -Scc
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [y/N] y
removing all files from cache...

Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...

[remove all the cached packages, except most recent 3 pacakge]
# paccache -r

17) Read more about pacman

Use the below commands to read more about pacman command information.

$ pacman -help
or
$ man pacman

Enjoy….)

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

2 Comments on “Pacman Command To Manage Packages On Arch Linux Based Systems”

Leave a Reply

Your email address will not be published. Required fields are marked *