With pacman, unlike APT or YUM, it has its own structure of commands. It’s a simple guide to all the must-know and some interesting additional commands for “pacman”.
The following guide applies to Arch Linux and all the other Arch-based Linux distros using pacman as the package manager. Sometimes, people prefer using Arch-based distros instead of the original one because of the complex installation mechanism. But the fact is, it’s quite easy! It’s just a matter of a little more focus and patience. Learn how to install Arch Linux.
Pacman command
There are tons of ways you can utilize pacman. Of course, you don’t need them on a regular basis. The following guide is a short collection of all the must-know and interesting methods of using pacman. The entire “pacman” guide is available at the official Arch Linux Wiki.
Update the database
For any package manager to work properly, it has to be in sync with the master servers. The same goes for pacman. To update the package database of pacman, run the following command:
It’s possible to force pacman to update the package database. This will recreate the package database. Use the following command:
Upgrade software
You can tell pacman to perform a full upgrade of the system. This will upgrade all the upgradable packages to the latest version.
You can combine forced package database update with the upgrade command. This will look something like this:
The next command will tell pacman to upgrade/downgrade the installed packages to the version that’s available on the master servers.
For example, if you have package “xyz-1.5” installed in your system but “xyz-1.4.9” is the latest version on the master server, pacman will downgrade to “xyz-1.4.9”.
Both can also be combined to perform a similar action.
Installing package(s)
Installing a package with pacman is really easy. Just run the following command:
This process will automatically identify all the necessary dependencies and take care of it.
In cases, packages come up with similar patterns. Instead of typing the same name over and over, use brackets as a shortcut. For example, for installing Python packages like pip, py, pytest, and pytest-runner, run the following command:
Note: Between the comma and the next package name, there MUST not be any space. Otherwise, the command won’t work.
In cases, you may just want to download the package. Pacman can be used to perform the action for you. Just use the “-Sw” flag.
Pacman will only notify you about the download size as the package is only going to be downloaded, no installed.
Pacman will download the package as <package_name>.tar.xz file and store it at “/var/cache/pacman/pkg” directory. In fact, all the Arch Linux packages are available in the .TAR.XZ format. Don’t worry; pacman can directly install a .TAR.XZ file provided that it’s a legit Arch Linux package file.
If you didn’t know, all the packages you download with pacman will always be there. Check out what packages are there.
Need to find out specific packages? Use “grep” to search for a specific package.
If you ever need to install/upgrade/downgrade any package, you know where to find the package.
Searching
If you’re confused with the package name, ask pacman to search it for you!
This method doesn’t have any color highlighting. Bummer! Don’t worry; pacman already knows how to colorize the output but the function is disabled by default. Want to see the colorful output? Edit the “pacman.conf” and uncomment the “Color” option.
Don’t forget to check out the result!
Besides the basic search mechanism, there are different ways of searching for a package. The basic one is quite useful, but sometimes, knowing other ways of doing the same thing can offer better benefits.
I love using “grep” for that purpose. Use pacman to list all the available packages and then, pipeline the output to “grep” to show all the necessary packages.
Did you notice the “-Ssq” flag? It tells pacman to print ALL the available packages, one at a line. I pipelined it to grep to show only the python3 packages. Sure, you don’t get the short package description.
There’s another built-in tool for doing all the searching for you: pacsearch. It offers a better view of the output with nice coloring and formatting. It should be available in your system. However, for some reason, if your system doesn’t have it installed, install it right away! It’s a part of the “pacman-contrib” package. Tell pacman to do the installation for you.
Now, let pacsearch to do the previous action.
Package information
The following command will list all the installed packages on your system.
It’s always going to be pretty long and confusing. If you’re looking for any specific package, use “grep”.
If you’re in need of detailed information about a certain package, use “-Qi” flag with pacman.
If you don’t pass any package name in the argument, it will show the information of all the packages in the pacman package database. Using “grep”, it’s possible to modify the output to show your desired information only.
This command flag “-Q” will only show the installed package information. Need to check out the latest information about a package? Use “-Si” flag instead.
Uninstallation
With pacman, uninstalling a package is more secure. Just run the following command:
Note: It will ALWAYS ensure that it doesn’t break the dependencies. If you’re ever trying to uninstall a dependency, it’ll block the uninstallation process.
If you’re willing to uninstall a package along with all the dependencies (no other packages depend on those dependencies), then use the following command structure:
It’s possible to force pacman to uninstall a package, no matter whether it breaks other dependencies or not. It’s an extremely dangerous way of uninstalling a package and strongly NOT RECOMMENDED if you’re unsure of what you’re doing.
Final thoughts
Pacman is a powerful package manager for Arch Linux. No package gets past it. Even if you install packages from other sources like the AUR repository, it must go through pacman to complete the installation. As one of the most important components of the Arch ecosystem, it’s no wonder you must confront the console window and ask pacman to perform certain tasks. Hopefully, this short guide was helpful in your journey with Arch Linux.