Arch Linux Pacman Basics

Posted by JeremyL on Wed 22 January 2014

Pacman is the Arch Linux package management tool. If you're unfamiliar with pacman, this will help you with some of the basics that you will more than likely want to learn to make your life on Arch much easier.

If you have yet to read the man page, now is a great time

man pacman

Before you follow along below we should first make sure that your box and its package database are up to date. Note if you have any major updates come in, such as a kernel it is best to reboot before continuing.

pacman -Syyu

What this command achieves is it tells pacman to sync, we are passing to 'y' which will have pacman to refresh all package lists even if it thinks they are up to date. This is useful if you have recently switched your mirror as well.

Searching for packages

You have many options when you're wanting to search for a package, each method giving you different outputs or control over the output.

For pacman you will want to remember the format it is expecting.

pacman -FLAG PACKAGE

The most simple method for search for a package in question is:

pacman -Ss PACKAGE_NAME

This can be overly verbose in some situations, returning everything that mentions the PACKAGE_NAME that you inserted.

You can also use a tool that comes prepackaged with pacman, pacsearch. It will add some features over the standard pacman search. You will get colored output and its category. Note, if you uncomment color in pacman.conf you will get colored output without pacsearch. An example of how to search with pacsearch:

pacsearch vim

Maybe you do not remember the entire name of the package you can search by what you remember, but the downfall will be the vast majority being not what you're searching for.

pacsearch nux

That will search for any package with the 'nux' in the name or description. To narrow down the output you can use regex.
If you just wanted to search for a package that begins only with nux

pacsearch ^nux

As you can see it gives no output now because nothing begins with nux. If you did say

pacsearch ^vim

You will get only the available packages that start with vim.

To make sure your regex works as intended you should always wrap in single quotes

pacsearch 'a\+\+'
community/tolua++ 1.0.93-1 
    Tool to integrate C/C++ code with Lua

Grep can also be useful in narrowing down your output

pacsearch linux | grep installed

With grep you can also get output from the lines before and after

pacsearch linux | grep installed -A 1 -B 1

A similar method using pacman would be

pacman -Qs linux | grep installed

Getting information about a package

If you need to get details about a package that is installed

pacman -Qi vim
Name           : vim
Version        : 7.4.135-1
Description    : Vi Improved, a highly configurable, improved version of the vi
                 text editor
Architecture   : x86_64
URL            : http://www.vim.org
Licenses       : custom:vim
Groups         : None
Provides       : None
Depends On     : vim-runtime=7.4.135-1  gpm
Optional Deps  : None
Required By    : None
Optional For   : None
Conflicts With : gvim
Replaces       : None
Installed Size : 2399.00 KiB
Packager       : Thomas Dziedzic 
Build Date     : Tue 07 Jan 2014 10:31:11 PM PST
Install Date   : Fri 10 Jan 2014 01:01:58 PM PST
Install Reason : Explicitly installed
Install Script : No
Validated By   : Signature

Be aware that if you do not pass a package name you will get the information output of all packages.

If you want to get information for a package you do not have installed

pacman -Si wordpress
Repository     : community
Name           : wordpress
Version        : 3.8-1
Description    : Blog tool and publishing platform
Architecture   : any
URL            : http://wordpress.org/
Licenses       : GPL
Groups         : None
Provides       : None
Depends On     : php
Optional Deps  : apache: Web server to run wordpress
                 cherokee: Lightweight Web server to run wordpress
                 mysql: Database server
Conflicts With : None
Replaces       : None
Download Size  : 4631.35 KiB
Installed Size : 16443.00 KiB
Packager       : Alexander Rødseth 
Build Date     : Sat 14 Dec 2013 04:45:20 PM PST
Validated By   : MD5 Sum  SHA256 Sum  Signature

Find files associated with a package with pacman. The following output is truncated.

pacman -Ql vim
vim /usr/
vim /usr/bin/
vim /usr/bin/rview
vim /usr/bin/rvim
vim /usr/bin/vim
vim /usr/bin/vimdiff
vim /usr/bin/vimtutor
vim /usr/bin/xxd

To get a less verbose output of the above, output truncated

pacman -Qlq vim
/usr/
/usr/bin/
/usr/bin/rview
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor
/usr/bin/xxd

Say you need to track down what package a file you need belongs to. You can install a tool called pkgfile.

pacman -S pkgfile

Now you need to update its database

pkgfile -u

Now lets find what packages provide xxd, as seen in the previous output from vim.

pkgfile xxd
extra/bash-completion
extra/gvim
extra/vim

Pacman local Disk consumption

The easiest way to get the total disk usage for each installed package you have on your box would be.

pacsysclean

There is also pacgraph which gives you a pretty graph if you're into that kind of thing.

pacman -S pacgraph

If you use the c flag it will output to console just as pacsysclean does. To just get a list of a the largest packages installed you can do

pacgraph -c | head

If you do not pass c it will produce the graph for you to view.

Installing or Downloading packages

To install a new package on your system

pacman -S PACKAGE_NAME

To easily install a group of packages with the same name scheme

pacman -S vim-{workspace,vcscommand,ultisnips}

There are times you may want to download a package from the Arch repo's but not actually install it.

pacman -Sw PACKAGE_NAME

To install a local package you have, such as one you downloaded or built with an AUR helper

pacman -U PATH/TO/PACKAGE.pkg.tar.xz

Upgrading packages

To upgrade a running system you will want to do

pacman -Syu

or to make sure you have the most current package database regardless of what pacman thinks the package database state is in

pacman -Syyu

If you just want to list what packages you have that are out of date

pacman -Qu

This will not display the version number. If this is something you need you can run the following command

pacman -Qi vim | grep "Version" | sed 's/^Version\s*:\s//'
7.4.135-1

If you wanted to compare the version numbers you could do something similar to the following

for i in $(pacman -Qqu)
do
  printf "$i: "
  printf "$(pacman -Qi "$i" | grep 'Version' | sed 's/^Version\s*:\s//') "
  echo   "$(pacman -Si "$i" | grep 'Version' | sed 's/^Version\s*:\s//')"
done

Modify to suit your needs

Downgrading packages

Sometimes an update will bork something on your box, this is rare but it does happen. While Arch Linux does not support or maintain depreciated packages you do have some choices. The most common way is to use the previous version from your pkgcache on the box. You installed packages are stored in

/var/cache/pacman/pkg/

Once you find the previous version you want to downgrade to you would install it as so

pacman -U /PATH/TO/PACKAGE_TO_DOWNGRADE.pkg.tar.xz

If you find you deleted the cache or just do not have the previous version for whatever reason you can try search on the Arch Linux Rollback Machine, or if on ArchLinux|ARM, you can use AdminEmpire's ArchLinux|ARM Rollback Machine.

Removing packages

To simply remove a single package, leaving all its dependencies behind

pacman -R PACKAGE_NAME

To remove the package and any dependencies that are not relied on by other packages

pacman -Rs PACKAGE_NAME

To delete the package, it's dependencies and everything they rely on as well. Be careful this can remove more than you want

pacman -Rnscd PACKAGE_NAME

Sometimes, though rare you might need to force the removal of a specific package

pacman -Rdd PACKAGE_NAME

Unofficial packages

It is best to become familiar to an AUR helper. Some options with these are packer and yaourt. I personally prefer packer over yoaurt, but it is a personal flavor and you might appreciate the overly verbose output of yaourt. The install and search commands are basically the same with your AUR helper as they are when using pacman.

Where to go from here?

You should make sure to read the Arch Linux wiki pages relating to pacman, to further learn about the very powerful pacman.