The Definitive Guide to Pacman Commands on Arch Linux

We independently review everything we recommend. When you buy through our links, we may earn a commission.

Definitive Guide to Pacman Commands Arch Linux

On distributions based on Arch, the package manager that is installed by default is Pacman. The following is an explanation of how you can use it to handle the management of packages on your system like a pro.

A Linux operating system cannot function without its package managers. They are the reason you are able to download and run the most recent software on your desktop computer and enjoy it. Pacman is the acronym that was created by combining the terms “package” and “manager,” and it is the package manager that is used by default on Arch-based computers.

Users who are familiar with other distribution families may find it difficult to adjust to the brief, one-character arguments used by Pacman, despite the fact that Pacman itself is quite simple to learn in comparison to its competitors. Now that we have everything out of the way, let’s have a look at Pacman, all of the many choices it provides, and how you can use it to manage packages on Arch Linux like a pro.

Pacman Commands Guide

Pacman, much like other Linux commands, adheres to a fundamental command syntax that includes a number of preset flags and arguments:

sudo pacman -options pkgname

…where -options are the flags that you use to invoke various functions and pkgname is the name of the package(s) that you wish to act upon….where -options are the flags that you use to call different functions.

Packages Can Be Upgraded With Pacman

The first thing you should do after installing Linux is to update any packages that are already installed. The following Pacman command will synchronize packages that have been installed with the repositories and upgrade them if newer versions are available:

sudo pacman -Syu

If you want to update just one specific package, you may do it by providing the name of the package as the argument for the -S flag:

sudo pacman -S pkgname

On the other hand, you can stop Arch Linux from upgrading a package if you don’t want it to. However, in order to accomplish this, you will need to alter the pacman.conf file that is found in the /etc directory.

Setting Up a New Package to Be Installed

Installing packages from the official Arch repositories is required in order to make your computer compatible with additional software. You will have an easier time downloading and installing packages when you use the -S option since it makes it possible to do so. The following is the command’s fundamental syntax:

sudo pacman -S pkgname

Installing the root package requires the following, for instance:

sudo pacman -S root

Output:

In order to install many packages with a single command, you must specify a list of packages that is separated by spaces.

sudo pacman -S pkgname1 pkgname2 pkgname3

Arch Linux, much like Ubuntu, has many repositories from which you may obtain the packages that you need. If there are many repositories hosting the same package under the same name, you will need to pick which one you want by providing the name of the repository you wish to use.

sudo pacman -S repo/pkgname

Installing a package from the “community” repository entails the following steps:

sudo pacman -S community/pkgname

You can download a package without actually installing it if you wish to retain a backup of particular programs for later use. To do this, use the -Sw option when downloading the item.

sudo pacman -Sw pkgname

Alternatively, you may use the package source URL to download and install a package directly on your computer. In order to accomplish this, you will need to use the -U switch and give the link to the archive:

sudo pacman -U https://example.com/pkgname.pkg.tar.zst

Installing a Local Package Using an Archive

In the event that you are unable to locate a particular package inside the Arch repositories, you can manually install it by downloading its tarball or archive from the internet and then using Pacman. The -U option enables the local installation of a package by using an archive that has been downloaded:

sudo pacman -U /path/to/archive/pkgname.pkg.tar.zst

Typically, Pacman will monitor the packages that have been installed by using the pacman -S pkgname command to do so, and it will check on a regular basis to see whether an update is available for those packages. If, on the other hand, you choose to install a package by utilizing a tarball that you downloaded, you will be required to manually check for changes to the package.

As a result, it is strongly suggested that you obtain the packages that you need from the official repository. You should only download and install a package locally using its archive if the package cannot be found in any of the official repositories. This is the only time you should do so.

Follow the structure of the following command if you wish to install a package from the package cache in order to perform a downgrade on it:

sudo pacman -U file://path/to/archive/pkgname.pkg.tar.zst

Look for an Available Installable Package

Using the -Q, -S, and -F parameters, respectively, you are able to search for packages in the local database, the sync database, and the file database that Pacman maintains.

Using the -Ss switch to search for a package in the sync database enables you to do so even if you are unsure of the precise name of the package.

sudo pacman -Ss query

For example:

Utilize the -Qs flag to conduct a search for a package that has previously been installed on your system:

sudo pacman -Qs query

Use the -Si option in conjunction with the command if you want to find out additional information about a package before actually installing it:

sudo pacman -Si pkgname

To display a list of orphaned packages, also known as installed dependencies that are not required by any of the packages already installed on the system:

sudo pacman -Qdt

In order to free up some space on your system, you may combine the command that was just mentioned with the command pacman -Rns as follows:

sudo pacman -Rns $(pacman -Qdt)

Uninstalling a Package

Use the -R option within Pacman whenever you wish to delete a package that was installed using it.

sudo pacman -R pkgname

Output:

The command that you just ran will just uninstall the package that you requested, and all of its dependencies will remain intact. Simply adding the -s parameter to the program will allow you to delete the package in addition to its dependencies:

sudo pacman -Rs pkgname

If the package you wish to get rid of is dependent on another package, you can get rid of both packages at once by using the -c flag, which is an extra option:

sudo pacman -Rsc pkgname

When you uninstall a package, Pacman will often save the configuration files connected with it and build a backup copy of those data. Use the -n argument in conjunction with the remove command to override this default behavior and uninstall packages without making a backup of the configuration files:

sudo pacman -Rns pkgname

Defragment the Package Cache to Free Up Some Hard Drive Space

The downloaded files are not deleted when a package is installed with Pacman. When the user removes them, they’re stored in the package cache until the user removes them. Cache files might take up a large portion of your system storage if they aren’t deleted.

To address this, it’s vital to clear the package cache on a regular basis.

paccache -r

Using the following command, you have the option of removing all of the cache files other than those associated with the packages that are presently installed:

pacman -Sc

The Differences Between Pacman, APT, and DNF: A Comparison

When compared to other package managers such as APT or DNF, the complex and non-intuitive flags that are utilized in the commands of Pacman might make it difficult for novice users to use the software. You can get things done fast without having to type many lines of commands into the terminal if you use Pacman, which is another benefit of using the program.

Let’s examine the differences and similarities between the commands used by APT and Pacman to update and upgrade packages. To accomplish this objective with a distribution that is based on Debian, you will need to perform two commands, which are as follows:

sudo apt update
sudo apt upgrade

You may alternatively concatenate the same two instructions by using the && operator, however although while this does the same thing, it is not as efficient as its Pacman equivalent:

sudo pacman -Syu

Overall, APT and DNF commands are self-explanatory and are easy to understand for Linux newcomers, whereas Pacman commands are concise and get more done in a few keystrokes.

Taking the next step! The Arch User Repository: A Field Guide

As you may already be aware, Pacman is unable to obtain packages from anywhere other than the official Arch repository. However, the majority of packages are hosted on the Arch User Repository, which is managed by the community (AUR). You will need an AUR helper such as yay in order to install packages obtained through the AUR.

The AUR is a repository that was developed and is being maintained by users specifically for the benefit of other users. Providing they have sufficient understanding of the AUR in the first place, anybody can contribute their own packages to the AUR in the form of PKGBUILDs.

Alex
We will be happy to hear your thoughts

Leave a reply

TopBestProductReview
Logo