Arch Linux pacman – Just the Most Useful Commands

Wading through man pages can be a tedious process. Often it’s not clear which options or commands you will be using 99% of the time and which ones are the more obscure options that are only occasionally useful. I was largely mystified by pacman’s man page until I decided to do an exhaustive search through it and distill it down to just the bare essentials. That is my goal with this article – to save you the work I had to do by providing a concise list of just the most useful command line options for pacman that you will be using in 99% of real-world cases. I’m going to show you just enough to be dangerous with pacman, but not enough to overwhelm you with superfluous information. The commands are organized by how relevant I expect them to be to a typical Arch user’s life, with more frequently-used commands appearing first, followed by less frequently-used but still valuable commands. Now let’s get started…

pacman -S – Install a package

This is probably the most frequently-used command. pacman commands almost always include a capital letter for a main command followed by optional lowercase letters for subcommands. The -S option to pacman means “Sync”, or “Sync a package with the package repository by downloading and installing it.” Using the -S option by itself simply installs a package and all of its dependencies. For example, to install the Lynx browser, you would use the following command:

$ sudo pacman -S lynx

pacman -Sy – Update the package databases

There are three databases that pacman keeps on your computer so it knows what packages are available. They are core, extra, and community. Before you install any packages, you have to make sure these databases are up-to-date. To do this, use the following command:

$ sudo pacman -Sy

You can also update the databases and install packages in the same command, like this:

$ sudo pacman -Sy lynx

This command will update the package databases and then install the Lynx browser.

pacman -Syu – Universal package upgrade

The -u option to pacman -S tells pacman to do a universal upgrade of all packages on the system. If you want to make sure the entire system is up-to-date without worrying about individual packages, and you’re not concerned about having to wait a while for packages to upgrade, use the command:

$ sudo pacman -Syu

This will upgrade any packages for which more up-to-date versions exist in the package repository. Packages that are already up-to-date will not be upgraded.

pacman -Sl – List all packages in the package repositories

This is in my opinion the most useful pacman function aside from just installing packages. It gives you an exhaustive list of all available packages, organized by repository. You can pipe this command into less and then scroll through the list or search for a specific title to see if you find anything you want to use. The command I typically use it:

$ sudo pacman -Sl | less

pacman -Sw – Download package files without installing anything

If you just want the package files, either so you can examine them or so you can install the package manually, you can use sudo pacman -Sw package to do just the download.

One case where this comes in handy is if you want to export a package to another Linux distro, for example if you have a Debian-based distro and you want to use a package that’s only available in the Arch repositories. Since pacman is a binary-based package manager, you can write a simple script to copy the files to their correct locations on the target system – no compilation necessary – as long as it’s based on the same CPU architecture.

pacman -R – Remove a package

This command is pretty straightforward. It simply removes a package that you have installed. This is the most basic package removal command, removing just the target package without removing any of its dependencies or dependents. To deal with these, use the next two commands…

pacman -Rc – Cascading removal

This removes a package and all of its dependents. That way you can be sure that you don’t leave any so-called “orphan” packages on your system that don’t have the proper dependencies.

pacman -Rs – Reverse cascading removal

This removes a package and any of its dependencies that don’t have other packages depending on them. You can combine this with the previous option to remove a package’s entire family tree of dependencies and dependants. For example:

$ sudo pacman -Rcs lynx

pacman -Ql – List all files included in a package

The -Q option to pacman is used for queries on packages. Most of these queries only work on packages that are currently installed. For queries on the online package repositories, you will typically use -S.

The -l option to pacman -Q lists all files included in a package that is installed on the system. This includes absolute filepaths to any executables, library files, header files, man pages, etc. that that package has installed in your filesystem.

pacman -Qu – List all out-of-date packages

This shows you a list of all packages on your system for which newer versions are available. Since newer versions of packages come out all the time, this list is likely to be fairly long, so you’ll probably want to pipe this into less to view the entire list.

$ sudo pacman -Qu | less

pacman -Qi and pacman -Si – View information about a package

Both these commands show information about a package, such as its version, website URL, license, dependencies, etc. There are a couple subtle differences though. First, pacman -Si shows general information while pacman -Qi shows more detailed information related to a specific installation of a package. Second, pacman -Si queries the package repository by default, whereas pacman -Qi queries installed packages, so if you want information about a package you haven’t installed yet, you’ll have to use pacman -Si.

pacman -U – Upgrade installation

This is very similar to pacman -S, with one subtle difference. pacman -U performs a “clean” upgrade of an existing package, meaning it removes all files for the old version of a package before installing the newer version.

pacman -Qk – Check to see if all files in a package are currently installed

This is the last query command on our list, and it is useful for verifying package integrity, and making sure none of the files used by a package got deleted at any point. If you get a message saying that files were deleted, you should reinstall the package, or use pacman -Sd to download the package and find the missing files and copy just those files to their correct locations.

pacman -Dk and pacman -Dkk – More package integrity checks

The -D option to pacman is for database commands. There are two specific database commands you’re likely to find yourself using. They are pacman -Dk and pacman -Dkk.

pacman -Dk queries the database entry for a package to see if there are any conflicts with other packages.

pacman -Dkk queries the database entry for a package to make sure all dependencies for a package are installed, and it reports any that aren’t.

There are over 75 different pacman commands listed in the pacman man page, but the 17 I listed here should be enough for the vast majority of your use of this package manager. I hope that now you feel ready to tackle just about any package management task in Arch Linux. See you next time.

One thought on “Arch Linux pacman – Just the Most Useful Commands

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s