Arch Linux is a popular Linux distribution that is revered for its simplicity and rolling release. It does away with many of the apps that ship with other distributions, and you are free to install the apps you want and need. However, you will have to be comfortable with its package manager – Pacman.
The Pacman package manager provides users with a simple way of managing packages. Packages can be managed from either official repositories or from a user’s own builds with Pacman. Follow this guide to master Pacman for Arch Linux.
Also read: 5 Arch Linux Distros That Are Easier to Install and Use
Updating the System
To update the system and all installed software, use the command:
pacman -Syu
To force a full refresh of the package database and update the system:
pacman -Syuu
Searching for Packages
If you want to install a package but can’t quite remember the package name, then you can do a keyword search directly from the terminal.
pacman -Ss {keyword}
For example, if you wanted to install gimp, you could do a search to see what the available packages are called.
pacman -Ss gimp
To search for installed packages:
pacman -Qs package_name
Installing Package/Software
You can use the command below to install single or multiple packages:
pacman -S package1 package2
However, it is better to update the system first before installing any packages. Use the following command to update and install software:
pacman -Syu package1 package2
Installing Packages from Third-Party Sources
You won’t always be installing packages from remote repositories. To install packages from a local directory, use the following:
pacman -U /path/to/packagefile_packagename.pkg.tar.xz
If you want to install a package from an unofficial repository, you can use the following command:
pacman -U https://packagesite.com/repo/packagename.pkg.tar.xz
Listing Installed Packages
If you just want to see all the installed packages in your system, use the command:
pacman -Ql
Download Packages
There are instances when you want to download a package but not install it. Use this command:
pacman -Sw package_name
Uninstall Package/Software
Package removal goes hand-in-hand with package installation. To remove a package and leave its dependencies behind, use the following command:
pacman -R package
If you want to remove a package and its dependencies that aren’t used by other packages, then run this command:
pacman -Rsu package
To check for orphan files:
pacman -Qdt
You can combine it with the following command to remove unused packages/orphans and their configuration files:
pacman -Rsnu $(pacman -Qtdq)
Remove Everything except the base system
This is kind of a way to start from scratch. If there is a need to “factory-reset” your system, the following two steps allow you to do so easily.
First, we need to make all installed packages become a “dependency:”
pacman -D --asdeps $(pacman -Qqe)
Next, we need to change the installation reason for essential packages (base system) to “as explicitly,” so they don’t get treated as orphans and get removed:
pacman -D --asexplicit base linux linux-firmware
Lastly, we will remove all the “orphaned” files:
pacman -Rns $(pacman -Qtdq)
Clearing Package Cache
Pacman doesn’t automatically clear out old or uninstalled versions of packages automatically. This allows for easy downgrades and easy reinstallation from the cache folder. However, as the cache grows inside, it may get out of hand. We have a dedicated article on clearing Pacman’s cache, but here is the gist:
This command clears out all of the cached versions of installed and uninstalled packages except for the three most recent ones.
paccache -r
To just clear out cached packages that aren’t currently installed, run the following:
pacman -Sc
If you want to completely clear your cache, run the command below. This will leave your cache folder completely empty.
pacman -Scc
Final Thoughts
Please note that this is by no means an exhaustive list. The possibilities are endless with Pacman, and you will need to spend some time getting familiar with other commands not mentioned here. However, Arch Linux’s documentation is excellent and is a good point of reference. With that being said, we have given you a solid base here. Learn these commands, and you will be quite competent with Arch Linux.
Our latest tutorials delivered straight to your inbox