The most useful Arch Linux commands you should know

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn the most useful commands that you should know if you are an Arch Linux user.

In Arch Linux and Arch Linux based distros, pacman is the default package manager that allows you to install, update or remove packages.

Whether you use arch linux on your server, or personal computer, knowing how to use pacman, is the key when it comes to maintaining your Arch Linux system.

How to update Arch Linux

To update your Arch Linux system, you can easily do so by using the -Syu option.

sudo pacman -Syu

How to install a package in Arch Linux

Installing a package in Arch Linux, and any Arch linux based system is easy, and you can do so by using pacman via the -S option.

sudo pacman -S package

Replace package with the name of the package that you want to install in your Arch Linux system.

For example, let's say you wanted to install firefox. To do so, simply run the following command.

sudo pacman -S firefox

How to install a local package in Arch Linux

To install a local package by using pacman, is very easy, and it can be done by using the -U option.

For example, we downloaded the latest version of firefox firefox-121.0-1-x86_64.pkg.tar.zst that can be found in the Aur repository, so to install it we can install it by running the command below.

sudo pacman -U firefox-121.0-1-x86_64.pkg.tar.zst

How to download a package in Arch Linux

pacman allows you to download a package without installing in your system. Let's say you want to download a package and want to store it in your hard disk so you can install it later on.

To do so, first download the package by using the -Sw option.

pacman -Sw package

For example, to download firefox simply replace package with firefox

sudo pacman -Sw firefox

Search for a package in Arch Linux

To search for a package in order to see if the package is available in the Arch linux repositories, you can do so by running the command below.

The syntax of searching for a package via pacman is

sudo pacman -sS package

For example, to search for nano text editor package, then you can do so running the following.

sudo pacman -sS nano

How to uninstall a package in Arch Linux

Uninstall a package

To uninstall only a single package from your Arch linux system, then simply use the -R option.

sudo pacman -R package

Uninstall a package along with the dependencies

In cases when you need to remove a package along with its dependencies, you can do so by using the -Rsc option.

sudo pacman -Rsc package

💡
Note: You should only remove the dependencies if you no longer need them, removing a package along with the dependencies may cause a lot of issues in your system if you are unsure which packages are getting uninstalled.

How to clean cache packages in Arch Linux

When you install a package in Arch Linux, the package gets downloaded in /var/cache/pacman/pkg/, which means even after uninstalling a package the package will still be there, so if you wanted let's say to reinstall it again, it would be reinstalled using the local package instead of downloading it.

To keep your system clean, and prevent the cached packages from taking too much space from your hard disk, you must clean these packages periodically.

Clean all cached packages, and keep only the last three versions.

To remove packages from the cache, and keep only the last three versions, run the command below.

sudo paccache -r

💡
Note: if you encounter the error "paccache command not found" when running the command above, it means that pacman-contrib package is not installed in your system. To fix this error, simply follow our tutorial "How to fix paccache command not found".

Clean all cached packages and keep only one version

To delete all cached packages, that might be installed or uninstalled in your system, and keep only the most recent version, then you can do so by running the following.

sudo paccache -rk1

Clean all cached packages without keeping any package

To remove all packages in the cache directory, and not keep anything, then simply run the following command.

sudo paccache -ruk0

Conclusion

By now you should be able to manage packages in your Arch Linux machine easily by using pacman.

Though we used Arch Linux in this tutorial, this tutorial should apply to any Arch based system that uses pacman as the default package manager.