Arch Linux Package Management Beginner's Cheat Sheet

flyingcakes

Snehit Sah

Posted on May 23, 2021

Arch Linux Package Management Beginner's Cheat Sheet

Introduction

Arch Linux comes with a powerful package manager called pacman. Often new users take time to figure out its commands because it does not have the usual 'obvious' commands like apt. So here is a short post about pacman commands.

Note : All pacman commands need to be run with superuser privileges. You need to prepend the commands with sudo for them to work. For the sake of brevity, I have omitted sudo.

Installing Packages

Download and Install

-S flag asks pacman to synchronize packages.

pacman -S package1 package2 package3
Enter fullscreen mode Exit fullscreen mode

will download install specified packages along with their necessary dependencies.

Selecting Repo in Case of Multiple Providers

By default, package is searched in repos in the order they are listed in /etc/pacman.conf.

In case a package is available from more than one source, then you can specify the repo name before package name to select the repo you want to download the package from. For example, I am using Endeavour OS, with Chaotic AUR added to my repo list. So, I can get the polybar package from two sources - EndeavourOS reop and Chaotic AUR repo. Since Endeavour OS repo has a preference in my pacman.conf, pacman will download polybar from that repo. However, if I want to download it from Chaotic AUR, I can run the following command.

pacman -S chaotic-aur/polybar
Enter fullscreen mode Exit fullscreen mode

Updating Packages

pacman -Syu
Enter fullscreen mode Exit fullscreen mode

will download new package database and then install the packages that have new updates available. This will include your kernel and other core packages too so make sure you have backups ready in case something goes wrong. Timeshift is a popular backup tool.

Searching For a Package

pacman -Ss search terms
Enter fullscreen mode Exit fullscreen mode

will search for the supplied terms and provide you with a list of matching entries.

Download But Don't Install

You may want to download packages, but not install them right away. This can be done by using the -w flag with one of the sync commands.

pacman -Sw reflector   # downloads reflector but doesn't install it
pacman -Syuw   # downloads available updates but doesn't install them
Enter fullscreen mode Exit fullscreen mode

About -Syy, -Sy and -Syuu

I edited this post and added this section because this deserves some attention. New users often use -Syyu to update packages. This is not a good practice, since if you frequently update, it will put extra load on the mirrors.

-Sy will update only those repos that are outdated. -Syy will force update all repos even if they are up to date. So avoid using -Syy. It is meant to be used in case your packaged database is corrupted or has some other issue.

Similarly, -Syuu will force package version to be in sync with the repo. In case your mirror has an outdated version of a package, it will be forcefully downgraded. Use -Syu to update packages.

And finally, never use -Sy alone. On Arch Linux, partial upgrades are not supported. If you do -Sy and then install a package, you will run into a case of partial upgrade and that may lead to problems.

In short, use -S to install and -Syu to update.

Details for a package

pacman -Si package-name
Enter fullscreen mode Exit fullscreen mode

will show details for the supplied package name.

Removing packages

Remove a Package

pacman -R package1 package2 package3
Enter fullscreen mode Exit fullscreen mode

will remove the specified packages.

Remove along with unneeded dependencies

pacman -Rs package1 package2 package3
Enter fullscreen mode Exit fullscreen mode

-s flag instructs pacman to remove any dependencies of the specified packages, that are no longer required by any other package on the system.

Removing groups of packages

pacman -Rsu gnome
Enter fullscreen mode Exit fullscreen mode

will remove the gnome group, but preserve any packages that are required by one or more packages installed on the system.

Query commands

List of installed packages

pacman -Q
Enter fullscreen mode Exit fullscreen mode

will output the list of installed packages along with their versions.

List packages no longer needed

If you remove packages without using the -s command, then unneeded dependencies can pile up on your system. You can list them with the following command

pacman -Qdtq
Enter fullscreen mode Exit fullscreen mode

To uninstall them, simply pipe them to pacman -Rs in with the following command

pacman -Qdtq | pacman -Rs -
Enter fullscreen mode Exit fullscreen mode

Packages no longer part of any repository

Sometimes, when a package is no longer maintained, it is removed from repositories. You may want to remove them since they are most certainly no longer required

pacman -Qm   # list foreign packages
pacman -Qmq | pacman -Rs -    # remove foreign packages
Enter fullscreen mode Exit fullscreen mode

Details for a package

pacman -Qi package-name
Enter fullscreen mode Exit fullscreen mode

will display information for a the supplied package name. Note that this works only for installed packages.

Know owner of a file

In case a system file is damaged, reinstalling the relevant package may help you fix it. In such case, you need to know which package owns the file in question.

pacman -Qo /usr/bin/zsh
Enter fullscreen mode Exit fullscreen mode

This command tells me package that owns the file I specified.

List explicitly installed packages

To get the list of package installed explicitly, meaning they are not installed as dependencies, run the following command

pacman -Qe
Enter fullscreen mode Exit fullscreen mode

The "explicitly installed" tag can be modified as described here.

List packages installed as dependency

To get the packages that were installed as a dependency, run the following command

pacman -Qd
Enter fullscreen mode Exit fullscreen mode

Again, this tag can be modified as described here.

Verify packages

pacman -Qk
Enter fullscreen mode Exit fullscreen mode

This will check if all the files for the installed packages are available on the system.

Database commands

Mark a package as explicitly installed

pacman -D --asexplicit package-name
Enter fullscreen mode Exit fullscreen mode

This will mark the package as explicitly installed and this package won't be considered when you run pacman -Qdtq or remove commands unless you explicitly specify the package name as a candidate for removal.

Mark a package as dependency

pacman -S --asdeps package-name
Enter fullscreen mode Exit fullscreen mode

Works as totally reverse of the previous command. Specified package will be considered for removal and also as unneeded dependency if no package depends on it.

File commands

List files installed by a package

pacman -Fl package-name
Enter fullscreen mode Exit fullscreen mode

will show the list of files that a package will install onto your system.

Search for file or filepaths

pacman -F filename
Enter fullscreen mode Exit fullscreen mode

will search for filename and list the packages that provide a file by that name. This is specially useful when I need to know which package provides a specific header file I need to use.

-F only accepts complete filenames, without path. To do a regex search, with filepaths and partial names, use the -x flag.

pacman -Fx path/to/file
Enter fullscreen mode Exit fullscreen mode

Conclusion

Thats all for this post.

You can follow my personal blog at https://flyingcakes85.github.io/blog/

Follow me on GitHub : flyingcakes85

💖 💪 🙅 🚩
flyingcakes
Snehit Sah

Posted on May 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related