So you’ve finally set up your computer to your liking, and organized and backed up all your dotfiles. If you want to save a list of all the software you’ve installed, you can use this simple pacman trick.

Pacman is a package management utility that tracks installed packages on a Linux system. It features dependency support, package groups, install and uninstall scripts, and the ability to sync your local machine with a remote repository to automatically upgrade packages. Pacman packages are a zipped tar format.

In order to save all installed packages, execute the following:

pacman -Qqe > .config/packages.txt

I’m putting the output into packages.txt in my .config folder, as this is a git repo that’s backed up to Github. The -Qqe options makes a neat list.

  • -Q: Query the package database. This operation allows you to view installed packages and their files, as well as meta-information about individual packages (dependencies, conflicts, install date, build date, size). This can be run against the local package database or can be used on individual package files. In the first case, if no package names are provided in the command line, all installed packages will be queried. Additionally, various filters can be applied on the package list.
  • -q: Show less information for certain query operations. This is useful when pacman’s output is processed in a script. Search will only show package names and not version, group, and description information; owns will only show package names instead of “file is owned by pkg” messages; group will only show package names and omit group names; list will only show files and omit package names; check will only show pairs of package names and missing files; a bare query will only show package names rather than names and versions.
  • -e: Restrict or filter output to explicitly installed packages. This option can be combined with -t to list explicitly installed packages that are not required by any other package.

Now in order to install all these packages on your other machine, execute the following:

sudo pacman -S - < .config/packages.txt

The -S flag synchronizes (installs) all packages listed in the packages.txt file.