The package manager is a key part of any Linux-based operating system. It is used to install and manage software packages on your system. Pacman is the default package manager for Arch-based Linux distributions. It provides an easier way to install, remove and update software packages to your system. Pacman uses simple compressed files as a package format and maintains a text-based package database.

In this post, we will show you how to use Pacman to manage packages on Arch Linux.

Step 1 – Configure Repository

By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:

nano  /etc/pacman.d/mirrorlist

Remove all lines and add the following lines:

## Score: 0.7, United States
Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.8, United States
Server = http://lug.mtu.edu/archlinux/$repo/os/$arch
Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.9, United Kingdom
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
## Score: 1.5, United Kingdom
Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch
Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch
## Score: 6.6, United States
Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch
## Score: 6.7, United States
Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch
## Score: 6.8, United States
Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch
## Score: 7.1, India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
## Score: 10.1, United States
Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch

Save and close the file, then update all the package indexes with the following command:

pacman -Syu

Step 2 – Install a Package with Pacman

The basic syntax to install any package on Arch Linux is shown below:

pacman -S package-name

For example, to install the Nginx pack

age, run the following command:
pacman -S nginx

You can also install multiple packages using the single Pacman command. For example, to install multiple packages unzip. curl and wget, run the following command:

pacman -S unzip curl wget

Step 3 – Remove a Package with Pacman

The basic syntax to remove a package in Arch Linux is shown below:

pacman -R package-name

For example, to remove a package named unzip, run the following command:

pacman -R unzip

If you want to remove the dependencies along with the package, use the -s option with the Pacman command:

pacman -Rs package-name

If your specified package acts as a dependency of another package, you can use the -c option to remove both packages:

pacman -Rsc package-name

If you remove a package using the Pacman command, it will create a backup of all configuration files associated with that package. You can remove packages without backing up config files, use the -n option:

pacman -Rns package-name

Step 4 – Download a Package Using Pacman

You can use the -Sw option to download any package without installing it on your system.

pacman -Sw package-name

For example, to download the Nginx package, run the following command:

pacman -Sw nginx

You should get the following output:

resolving dependencies...

Packages (4) geoip-1.6.12-2  geoip-database-20220823-1  mailcap-2.1.53-1  nginx-1.22.0-2

Total Download Size:  2.75 MiB

:: Proceed with download? [Y/n] y
:: Retrieving packages...
 geoip-database-20220823-1-any                              2.1 MiB  5.17 MiB/s 00:00 [#################################################] 100%
 nginx-1.22.0-2-x86_64                                    585.8 KiB  7.15 MiB/s 00:00 [#################################################] 100%
 geoip-1.6.12-2-x86_64                                     86.9 KiB  1609 KiB/s 00:00 [#################################################] 100%
 mailcap-2.1.53-1-any                                      29.5 KiB   590 KiB/s 00:00 [#################################################] 100%
 Total (4/4)                                                2.8 MiB  3.29 MiB/s 00:01 [#################################################] 100%
(4/4) checking keys in keyring                                                        [#################################################] 100%
(4/4) checking package integrity                                                      [#################################################] 100%

Step 5 – Search for a Package Using Pacman

Pacman provides a search capability that allows you to search for packages in the local database.

The basic syntax to search for any available package is shown below:

pacman -Ss query

For example, to search for a package named Docker, run the following command:

pacman -Ss docker

You should get the following list:

community/bashbrew 0.1.1-2
    Canonical build tool for Docker official images
community/container-diff 0.17.0-2
    Diff your Docker containers
community/docker 1:20.10.18-1
community/docker-buildx 0.9.1-1
    Pack, ship and run any application as a lightweight container
    Docker CLI plugin for extended build capabilities with BuildKit
community/docker-compose 2.11.2-1
    Fast, isolated development environments using Docker
community/docker-machine 0.16.2-5
    Machine management for a container-centric world
community/docker-scan 0.20.0-1
    Docker Scan is a Command Line Interface to run vulnerability detection on your Dockerfiles and Docker images
community/drone-runner-docker 1.8.2-1
    Drone pipeline runner that executes builds inside Docker containers
community/kompose 1.26.0-2
    Docker compose to Kubernetes transformation tool
community/molecule-docker 2.1.0-1
    Molecule Docker Driver

To search for a package already installed on your system, use the -Qs option:

pacman -Qs wget

You should see the following output:

local/wget 1.21.3-1
    Network utility to retrieve files from the Web

To list orphaned packages, run the following command:

pacman -Qdt

To find more information about any package, run the following command:

pacman -Si nginx

You will get the following output:

Repository      : extra
Name            : nginx
Version         : 1.22.0-2
Description     : Lightweight HTTP server and IMAP/POP3 proxy server
Architecture    : x86_64
URL             : https://nginx.org
Licenses        : custom
Groups          : None
Provides        : None
Depends On      : pcre2  zlib  openssl  geoip  mailcap  libxcrypt
Optional Deps   : None
Conflicts With  : None
Replaces        : None
Download Size   : 585.77 KiB
Installed Size  : 1693.74 KiB
Packager        : Giancarlo Razzolini <[email protected]>
Build Date      : Fri 10 Jun 2022 01:45:12 PM UTC
Validated By    : MD5 Sum  SHA-256 Sum  Signature

Step 6 – Clean Package Cache

When you install a package using the Pacman command, it doesn’t remove the downloaded files. In this case, you can keep the cache files of currently installed packages and remove the rest using the following command:

pacman -Sc

You will get the following output:

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

To remove unwanted dependencies, run the following command:

pacman -Rns $(pacman -Qdt)

Conclusion

In this post, we explained how to manage packages with Pacman package manager on Arch Linux. This will help you to manage packages easily on Arch Linux. You can choose one of our dedicated server hosting from Atlantic.Net! to use the Pacman.