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
Download and Install
-S flag asks pacman to synchronize packages.
pacman -S package1 package2 package3
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
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
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
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
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.
-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
will show details for the supplied package name.
Remove a Package
pacman -R package1 package2 package3
will remove the specified packages.
Remove along with unneeded dependencies
pacman -Rs package1 package2 package3
-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
will remove the gnome group, but preserve any packages that are required by one or more packages installed on the system.
List of installed packages
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
To uninstall them, simply pipe them to
pacman -Rs in with the following command
pacman -Qdtq | pacman -Rs -
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
Details for a package
pacman -Qi package-name
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
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
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
Again, this tag can be modified as described here.
This will check if all the files for the installed packages are available on the system.
Mark a package as explicitly installed
pacman -D --asexplicit package-name
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
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.
List files installed by a package
pacman -Fl package-name
will show the list of files that a package will install onto your system.
Search for file or filepaths
pacman -F filename
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
pacman -Fx path/to/file