Getting started with Pacman

About Pacman

Pacman, stands for Package Manager, is the default and simple library-based command line package management tool for Arch Linux and its derivatives. It allows us to easily install, remove, update, and upgrade packages along with all required dependencies. In short, Pacman will keep your Arch Linux system up-to-date by synchronizing packages with the remote master server. Pacman generally uses the .pkg.tar.xz package format, and it is written using C programming language.

As you probably know, unlike other Linux distributions, Arch Linux doesn’t have any GUI package manager. For example, Ubuntu has a GUI package manager called software center to install, update, upgrade, and remove packages. But in Arch Linux, there is no such thing. Pacman is a command line package manager.

In this tutorial, let me see you how to use pacman to install, remove, update, and upgrade packages in Arch Linux with simple examples.

1. Refresh package lists

Like in all Linux operating systems, before installing any packages, or updating the system, we must update the package lists:

7. Remove a package

To remove a single or group of packages, we use -R parameter with pacman command.

Say for example, I want to remove the mate package.

To do so, run:

# pacman -R mate

Be mindful that the above command will only the actual package you specified. The dependencies will still remain in the hard drive.

In order to remove a package with all its dependencies, run the following command:

# pacman -Rs <package-name>

Example:

# pacman -Rs mate

This command will completely remove mate package and all dependencies.

Now, wait. What about the configuration files? Pacman keeps the important configuration files with the extension: .pacsave while removing packages.

If you no longer want them and want to free up hard drive, you can get-rid of that files with command:

# pacman -Rsn mate

The above command will completely remove mate desktop session along with all required dependencies and configuration files.

Be careful while using the above command. You might accidentally delete some important dependencies required by another software.

So, to remove a package, which is required by another package, without removing the dependent package, use the following command:

# pacman -Rdd <package-name>

As you might know, there will still be some orphaned (unused) packages in your Arch Linux after removing a package. These orphaned packages are not required anymore, so we can get rid of them to free up some space.

To check if your Arch Linux has any orphaned package, run:

sudo pacman -Qdt

This command will display a list of unused packages.

To remove these packages, run:

sudo pacman -Rns $(pacman -Qdtq)

8. Search for packages from local database

It means querying a single or the list of packages from the local database i.e the cache folder.

To search for a specific package, for example vlc, from the local database, run:

# pacman -Q vlc

Sample output:

vlc 2.2.2-3

To search already installed packages, use the -s flag.

# pacman -Qs vlc

Sample output:

local/vlc 2.2.2-3
A multi-platform MPEG, VCD/DVD, and DivX player

To search a package from the local database with detailed information, run:

# pacman -Qi vlc

Similarly, you can search multiple packages from the local database with command:

This will give you an idea which package consumes more disk space, so that you can uninstall them it they are no longer needed.

12. Downgrade packages

This is something important that you need to pay attention. Let us say you want to install a new vlc package version. After installing the new vlc version, you notice that the application is constantly freezing, or broken, or not working at all. What would you do? In such cases, you can easily downgrade the vlc to the old and stable version. This can only be possible if you haven’t clear your cache folder.

basically, all packages that we downloaded during the installation will be stored in the cache directory i.e /var/cache/pacman/pkg/. If you find a package is not working after upgrading it, you can easily downgrade it to its previous stable version.

To do so, remove the new version using command:

# pacman -R vlc

And then, go to the cache directory:

# cd /var/cache/pacman/pkg/

Now, install old version with command:

# pacman -S vlc-2.2.2-3-x86_64.pkg.tar.xz

Similarly, you can downgrade all problematic packages to their old versions.

13. Clean up package cache

Like I said, all packages that we downloaded during the installation will be stored in the cache directory i.e /var/cache/pacman/pkg/. If you don’t remove them periodically, it will slowly eat up your hard drive space, and sooner or later you could end up with low disk space.

So it is good to remove the cache periodically. Also, you must know that there are good and bad sides.

The good side is, as I mentioned above, you can downgrade a package to its old version whenever you want. If you find a package is not working properly after upgrading your system, you can easily downgrade it to the old version.

The bad side is disk space. If you have small size of root partition, and If you don’t clear cache folder periodically, then you’ll be surely run out of disk space soon. So, it is a good idea to clear up the cache from time to time.

To clear the cache folder, run the following command:

# pacman -Sc

The above command will remove all packages which are not installed locally from the cache folder.

To completely remove all packages (Whether they are installed or not installed) from the cache:

# pacman -Scc

Warning: There is no way to get back the cleared cache. So, be very careful before clearing the cache.

That’s all for now folks. I hope you got some basic ideas of Pacman command usage. If you think that I missed anything, please let me know in the comment section below. I will update this guide as soon as possible.

Thanks for reading. If you find this tutorial useful, please share it on your social networks an support OSTechNix.