How to use Pacman on Arch Linux

This article seeks to provide you with a basic overview and understanding of the usage and implementation of the Pacman package manager on an Arch Linux OS.

A package manager is a key differentiator for various Linux operating system distributions. Pacman is one of them. It serves its package management role under the Arch Linux OS distribution. The main functional goal of Pacman is simple and straightforward.

It helps Arch Linux users manage OS packages without the involvement of too many technicalities. These packages either reside on users’ own builds or from the OS’s official repositories.

Arch Linux’s packages mentioned sources have a package list configuration synchronized with a secondary master server. This package list is referenced by the master server when an Arch Linux user makes a random system update query. In short, the user is the client that communicates with the master server when a package installation or download is needed.

The Pacman package manager initiates the simple commands that make these installations and downloads possible. However, sometimes the used command sequences require the Arch users to specify other mandatory package dependencies. Interestingly, the C programming language provided the main source code for Pacman.

Pacman usage on Arch Linux

This article seeks to provide you with a basic overview and understanding of the usage and implementation of the Pacman package manager on an Arch Linux OS. To understand the usage and implementation of Pacman, its associated operations need a categorical presentation. Therefore, we will start with the basic Pacman operations you might be familiar with and advance to the much more complex operations you are yet to explore.

Packages installation

Before undertaking package installation, there is the need to understand the basic attributes of a package. Since an archive generalizes a package, it should contain the following:

  • An application’s compiled files
  • An application’s metadata. It could be the app’s version, name, or even dependencies.
  • The package manager’s (Pacman) directives together with its installation files.
  • The optional inclusion of extra files like a start/stop script. These files make the life of an Arch Linux user much easier.

With Pacman package manager, you as an Arch Linux user have the power to install, update, and remove various Linux OS packages from your computer. Packages are the perfect alternatives to self-recompiling and self-installation of normal OS programs. When dealing with OS packages instead of direct installation of programs, you reap the following benefits:

  • Packages are easily updatable. Every time you run a system update, the OS will also update the packages provided the package installation was linked to an official repository.
  • Dependency checks are available. With Pacman, your OS package installations won’t fail because of broken packages. Pacman only needs the targeted program’s name, and it will sort out its dependency needs.
  • Clean package removal. Pacman directly accesses all your installed packages by referencing the packages list the OS creates. So you won’t face any challenges when wanting to uninstall a package from your system completely.

Dealing with specific packages

Under Arch Linux, you can install specific packages together with their dependencies. You can even install more than one package. The following Pacman command should shed some light on the installation approach.

# pacman -S package_1 package_2

On this command, package_1 and package_2 symbolize the package name you will key in for the installation to commence.

You can also use regex to install several packages at once.

# pacman -S $(pacman -Ssq package_regex)

You can learn more about this implementation here.

When pursuing package installation under Arch Linux, you will find that some packages exist in multiple versions because of different repositories. For example, it could be a testing repository or an extra repository. Let’s say we are interested in a package under the testing repository. To install it, we first need to specify this repo’s name before the actual package name. Consider the following implementation of this rule.

# pacman -S testing/package_name

If you have several packages you wish to install, and all of them have a similar name pattern, you will find the use of curly brace expansion to be ideal. For example, consider the following use case implementation.

# pacman -S plasma-{nm, desktop, mediacenter}

The use of these curly brace expansions can be further implemented in complex package installation routines, as demonstrated by the following use case.

# pacman -S plasma-{workspace{, -wallpapers}, pa}

The above example shows how you can use curly brace expansions to many levels when dealing with Arch Linux packages installation.

Dealing with virtual packages

Anything virtual is dependent on the existence of something else. It is the same case with virtual packages. Because they are not independent, their existence is tied to other packages. Since virtual packages are tied to these specific packages, they prevent them from having other package dependencies.

Since a package name is not enough to install these virtual packages, you only need to know the name of the primary package associated with this virtual package. By knowing the package name that hosts the virtual package, you will install it with the normal Pacman package installation command.

# pacman -S primary_package_name

Installing package groups

For an experienced Arch Linux user, dealing with packages defined in package groups is no news. The installation of these packages is usually simultaneous. Consider the use case of the following command.

# pacman -S gnome

Issuing this command prompts the selection of the needed packages from an active gnome group. The package group may or may not contain too many packages. If the packages are too many and you only need to install a few, an ideal command syntax is needed. In normal circumstances, you might be forced to enter too many numbers to exclude the installation of specific packages.

Using the following syntax, it is easy to exclude the packages you don’t need to install through ranges.

Enter a selection (default=all): 1-12 16

The response to the above command syntax selects packages 1 to 12 and 16 for installation. The rest of the packages are ignored.

The above command syntax follows an inclusive approach to install package groups. However, if you prefer going with an exclusion approach, you should consider the following syntax.

Enter a selection (default=all): ^4-9 ^3

All packages are selected for installation in the above case except for packages 4 to 9 and 3.

Since the above use case references a package group called “gnome”, you might want to preview the packages associated with this group after you have successfully installed the packages. In this case, you will use the following command syntax:

# pacman -Sg gnome

More on Arch Linux package groups are available on this link.

Once you prompt Pacman to install a package and the package already exists on your system, this package manager will re-install that package even if the installed version is up-to-date. On the other hand, using “–needed” as an additional argument in the installation command will overlook the re-installation of that package.

Uninstalling packages

If you want to uninstall or remove a package from your Arch Linux system, you should reference the following command syntax.

# pacman -R name_of_package

The above uninstallation only removes the package from your system but not the dependencies associated with it. If you want to eliminate both a package and its associated dependencies, consider the following command syntax.

# pacman -Rs name_of_package

An alternative to the above command helps get rid of package groups which tend to be a challenge.

# pacman -Rsu name_of_package

The following command eliminates a specific package, its dependencies, and every other package depending on this targeted package.

# pacman -Rsc name_of _package

Be careful with using this command so that you do not get rid of a package you might later need.

To get rid of a package required for the functionality of another package without getting rid of the packages that depend on it, you can reference the following command syntax. Using this command can break your Arch system. Only use the command when you are certain of what you are doing.

# pacman -Rdd name_of_package

When you remove certain packages associated with your Arch applications, important configuration files are saved by Pacman under a “.pacsave” extension. However, when you include the -n option in your uninstallation commands, these backup configuration files won’t be created. For example, consider the following use case.

# pacman -Rn name_of_package

An exception is that if the app itself creates the configurations, Pacman won’t get rid of them.

Upgrading packages

With just a single Pacman command, you should be able to update and upgrade all the packages on your Arch system. Depending on how recent you made an effort to update your system, the update and upgrade process could take some time. The upgrade process considers packages residing in the configured repositories. In this case, local packages are excluded. Use the following command:

# pacman -Syu

Querying package databases

If you want to query your Arch system’s package database, consider using the following commands.

# pacman -Q --help

The above command queries the system’s local package database.

# pacman -S --help

The above command queries the system’s sync database.

# pacman -F --help

The above command queries the system’s files database.

The flags -Q, -S, and -F are critical, and you should never omit them.

You can also search the system’s database for existing packages by querying the packages’ names and descriptions.

# pacman -Ss string1 string2 …

The -s option is associated with a built-in ERE (Extended Regular Expression). Its usage may lead to undesirable terminal outputs. Its functional usage can be limited to focus on the package name alone and ignore other fields like the package description. Consider the following usage when querying about the vim editor.

# pacman -Ss '^vim-'

If you are interested in searching packages already installed in your system, take the following command approach.

# pacman -Qs string1 string2 …

If you want to search or reference remote packages for specific package file names, use the following command syntax.

# pacman -F string1 string2 …

If you need more information about a targeted package based on its name, consider the following command approach.

# pacman -Si name_of_package

If you want to query some info about a locally installed package on your Arch system, consider the following command syntax.

# pacman -Qi name_of_package

The locally installed package is sometimes associated with backup files. To see these files together with their associated modification states, use an extra -i flag.

# pacman -Qii name_of_package

Sometimes the package you install will also install other files. To see these files, consider the following Pacman command syntax.

# pacman -Ql name_of_package

Remote packages installation will also tend to initiate the installation of other package-associated files. To see these remotely installed files, reference the following Pacman command syntax.

# pacman -Fl name_of_package

Sometimes the package-installed files might need verification to be certain of their presence. Use the following command syntax.

# pacman -Qk name_of_package

If you need a thorough verification step, pass the -k flag twice.

# pacman -Qkk name_of_package

You might also need to associate an installed file to its package installer on your Arch system. For this to happen, you will have to provide the path to that file, as demonstrated by the following command.

# pacman -Qo /path/to/name/of/file

To associate an installed file to a remote package installer, reference the following command syntax.

# pacman -F /path/to/name/of/file

You might also have package dependencies on your system that are no longer required. These dissociated dependencies are also referred to as orphans. To list them, refer to the following command syntax.

# pacman -Qdt

Your Arch system might also have installed packages that were dependent on other packages but no longer required. To list them, use the following command syntax.

# pacman -Qet

Pactree

Most installed packages are also associated with a dependency tree. To view this tree, reference the usage of the following command.

# pactree name_of_package

Database structure

The Arch Linux system path “/var/lib/pacman/sync” points to the primary location of the Pacman databases. Also, all of Arch’s repositories are specified in the path that leads to the file “/etc/pacman.conf”. For each repo specified, a corresponding database file is also created in the specified paths-to-files.

Cleaning package cache

The Arch system path “/var/cache/pacman/pkg/” is the storage location of Pacman’s downloaded packages. Old or uninstalled package versions are not removed by the Arch system automatically. This system feature offers several advantages.

  • It is much easier to downgrade an installed package based on its version number.
  • Since this system cache folder holds uninstalled packages, it is flexibly easier to reinstall that same package when needed instead of freshly downloading it from an active repository.

On the other hand, if this cache folder is left unchecked, it could grow indefinitely. Therefore, you should make an effort to clean it deliberately. The following command efficiently cleans the system cache of uninstalled and installed packages’ versions except for the Arch system’s most recent 3 package entries.

# paccache -r

Enabling and starting the “paccache.timer” will create a weekly schedule of discarding unused system packages.

When caching out these package versions from your system, you can be specific with the ones you want to retain. For example, if you want to leave one past version, consider the following command syntax.

# paccache -rk1

To get rid of uninstalled packages regardless of their versions, use the following command syntax.

# paccache -ruk0

More options on using paccache can be found by running the following command on your terminal.

# paccache -h

To get rid of unused sync database and not-yet-installed cached packages, execute the following command.

# pacman -Sc

If you want to clean the system cache completely, you might need a more aggressive command. For example, the following command will empty your Arch system cache folder.

# pacman -Scc

Other useful commands

If you want to only download an Arch Linux package without installing it at first, use the following command syntax.

# pacman -Sw name_of_package

If the local package you wish to install does not reside in a remote repository, you should consider the following package installation approach.

# pacman -U /path/to/name/of/package-version.pkg.tar.zst

You might want the local package copy to reside in Pacman’s system cache. Refer to the following command syntax.

# pacman -U file:///path/to/name/of/package-version.pkg.tar.zst

The installation of a remote system package or one that does not reside in a defined repo is possible through the following command syntax.

# pacman -U http://www.example_link.com/repo/example.pkg.tar.zst

Before Pacman installs or remotes a targeted system package, it will first ask the Arch system user to confirm its installation or uninstallation.

Final note

The Arch system path to the file “/etc/pacman.conf” contains Pacman’s primary settings. As an Arch system user, you can access this file and customize the performance of your installed programs to specific preferences. More on this setup is found at pacman.conf(5) official documentation.

In summary, the Pacman package manager has a lot to offer other than installing, updating, and removing Arch packages. You can use it to view changelogs, installed applications, group packages, and explicitly installed packages. This list continues. The more you use and interact with Pacman on your Arch system, the more you will explore and discover its unlimited potential.

More operational examples and implementations of the Pacman package manager are available on Arch Linux’s official site.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

22,858FansLike
437FollowersFollow
16SubscribersSubscribe

Latest Articles

Suggested

How to create your own Minecraft Server

Minecraft is a well-known sandbox game for a variety of purposes. It's simple to pick up and practice, gives you the freedom to do anything you want in the game, is virtually limitless, and allows you to create whatever you want if you have the imagination.

Featured

More Articles Like This