arch, linux

Save and restore your Arch Linux packages

Lately, I have been reinstalling Arch from scratch on several machines. When doing so, it is very handy to replicate your packages and that is actually very easy to do with Arch Linux.

Create a package list

The following command creates a list with your packages, that you can curate and store under private versioning control.

pacman -Qqen > pkglist.txt

And this will create a list with the packages that were installed external to the pacman database, either manually installed or from the AUR.

pacman -Qqem > localpkglist.txt

Also, I store my dot files and some of my etc files in a private git repo.

Install from the package list

In order to install from these lists you can do

sudo pacman -S --needed $(comm -12 <(pacman -Slq|sort) <(sort pkglist.txt) )


pacaur -S --noedit --noconfirm --needed localpkglist.txt

Other maintenance tasks

This will remove all packages that are not in list. It can be handy to clean up the list and update your system to it.

sudo pacman -Rsu $(comm -23 <(pacman -Qq|sort) <(sort pkglist))

This will remove packages that were installed as dependencies and are no longer needed.

sudo pacman -Rs $(pacman -Qtdq)

Get a backup of modified configuration files ( taken from ms pacman )

pacman -Qii | awk '/^MODIFIED/ {print $2}' | tar -n -cvzf -T -

Well, I know there’s hundreds of ways to do this kind of task but here’s my two cents!

Author: nachoparker

Humbly sharing things that I find useful [ github dockerhub ]


  1. Is it not better to update you Pacman Database, instead? If you recreate Pacman database based on that handy list, tough, packages may end up not being marked as explicit or implicit install, or as deps, as the original system… Oh well, that is how I see it so I *also* have a backup copy of /var/lib/pacman/local/

Leave a Reply

Your email address will not be published. Required fields are marked *