Home Arch Linux Getting Started With Pacman In Arch Linux

Getting Started With Pacman In Arch Linux

By sk
Published: Last Updated on 5.6K views

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.

Pacman Command 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:

To do so, run the following command as root user:

# pacman -Syy

Sample output:

:: Synchronizing package databases...
 core 122.6 KiB 69.9K/s 00:02 [######################] 100%
 extra 1745.3 KiB 38.5K/s 00:45 [######################] 100%
 community 3.4 MiB 243K/s 00:14 [######################] 100%
 multilib 162.1 KiB 264K/s 00:01 [######################] 100%
 archlinuxfr 11.2 KiB 338K/s 00:00 [######################] 100%

root@server:~_001

2. Install a specific package

To install a particular package, for example vlc player, we use the following command:

# pacman -S vlc

root@server:~_002

The above command will install vlc package along with all required dependencies.

Similarly, you can install multiple packages at once.

For example, to install vlc and firefox, we can use the following command:

# pacman -S vlc firefox

3. Download a package

Sometimes, you might want to just download a package and keep it in your cache without installing it. You might plan to use the downloaded packages in future.

To do so, run:

# pacman -Sw <package-name>

Example:

# pacman -Sw vlc

The above command will only download the vlc package, and keep it in the cache folder.

Pacman stores all downloaded packages in /var/cache/pacman/pkg/ folder.

# ls /var/cache/pacman/pkg/

root@server:~_004

In case, you want to install the downloaded packages, go to the cache folder and enter the following command:

# cd /var/cache/pacman/pkg/
# pacman -U <package-name>

Example:

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

Do not confuse with -U flag. It doesn't mean uninstall. We use this flag to install packages from the local cache.

4. Install a package group

We can install a package group. Say for example, you might want to install KDE plasma desktop or MATE desktop. To do so, just run:

# pacman -S plasma-desktop
# pacman -S mate

This command will install the MATE or KDE plasma desktop session with all required dependencies.

5. Update / Upgrade a package

To update a single package, run:

# pacman -S <package-name>

Example:

# pacman -S vlc

To update all packages in your system, run:

# pacman -Syu

The above command will upgrade your Arch Linux to the next available latest version.

6. Skip update / upgrade a package or a package group

Sometimes, you might want keep the old version of a particular package while upgrading your Arch Linux.

To skip updating or upgrading a package, use command:

# pacman -Syu --ignore=grep

Sample output:

:: Synchronizing package databases...
 core 122.6 KiB 69.5K/s 00:02 [######################] 100%
 extra 1745.3 KiB 152K/s 00:12 [######################] 100%
 community 3.4 MiB 37.2K/s 01:33 [######################] 100%
 multilib 162.1 KiB 107K/s 00:02 [######################] 100%
 archlinuxfr is up to date
:: Starting full system upgrade...
warning: grep: ignoring package upgrade (2.23-1 => 2.24-1)
 there is nothing to do

root@server:~_011

To skip a package group, run:

# pacman -Syu --ignoregroup=mate

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 -Rns 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

root@server:~_007

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

# pacman -Q string1 string2

To view the complete list of installed files by the package, run:

# pacman -Ql vlc

root@server:~_009

9. Search for packages from sync database

To search a package from a sync database (remote server), run:

# pacman -Ss vlc

Sample output:

extra/phonon-qt4-vlc 0.8.2-4
 Phonon VLC backend for Qt4
extra/phonon-qt5-vlc 0.8.2-4
 Phonon VLC backend for Qt5
extra/vlc 2.2.2-3 [installed]
 A multi-platform MPEG, VCD/DVD, and DivX player
community/npapi-vlc 2.2.2-1
 The modern VLC Mozilla (NPAPI) plugin

root@server:~_008

To display the detailed information of the given package from the sync database, run:

# pacman -Si vlc

root@server:~_010

Pacman also ships with pacsearch utility that displays the search results with color highlighting, and it displays whether the package is installed or not.

The typical usage of pacsearch command will be:

# pacsearch vlc

Sample output:

extra/phonon-qt4-vlc 0.8.2-4
 Phonon VLC backend for Qt4
extra/phonon-qt5-vlc 0.8.2-4
 Phonon VLC backend for Qt5
extra/vlc 2.2.2-3 [installed]
 A multi-platform MPEG, VCD/DVD, and DivX player
community/npapi-vlc 2.2.2-1
 The modern VLC Mozilla (NPAPI) plugin

root@server:~_012

As you see in the above output, pacsearch utility shows that vlc is installed.

10. List all unused (orphan) packages

To view all unused packages that are no longer needed as dependencies, use -dt parameter as shown below.

# pacman -Qdt <package-name>

11. Check which packages are taking up most space

Pacman has a nice utility called "pacgraph" that shows which packages are eating up most space in your hard drive.

Install pacgraph utility first.

# pacman -S pacgraph

Then, run the following command to find which package occupies more space:

# pacgraph -c

Sample output:

Autodetected Arch.
Loading package info
Total size: 1302MB
 407MB vlc
 201MB linux
 130MB gcc
 100MB pacgraph
 29425kB grub
 19300kB make
 15617kB yaourt
 290kB vi
 231kB pciutils
 186kB iputils
 164kB patch
 114kB pkg-config
 76kB logrotate
 55kB pcmciautils
 50kB os-prober
 31744B aurvote
 27648B which
 5120B systemd-sysvcompat

If you just wanted to show top biggest packages, run:

# pacgraph -c | head

Sample output:

Autodetected Arch.
Loading package info
Total size: 1302MB
 407MB vlc
 201MB linux
 130MB gcc
 100MB pacgraph
 29425kB grub
 19300kB make
 15617kB yaourt

As you see in the above output, vlc package is eating up more space.

Like wise, to check which packages are eating up lowest size, run:

# pacgraph -c | tail

Sample output:

 231kB pciutils
 186kB iputils
 164kB patch
 114kB pkg-config
 76kB logrotate
 55kB pcmciautils
 50kB os-prober
 31744B aurvote
 27648B which
 5120B systemd-sysvcompat

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

root@server:~_013

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.

Reference Links:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

1 comment

Александр Костик January 10, 2018 - 11:27 pm

thanks !
very useful tutorial !!!
keep going 🙂

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More