Keep Arch updated and pinky clean

Last edited on 2022-07-24 Tagged under  #arch   #linux   #bash   #programming 

I have started using Arch Linux as my daily-use desktop OS. Part of good system hygiene is keeping the system regularly updated.

This is how I do it ...

1. Lists of installed packages

Generate a list of packages found in the sync database (Arch official repositories) ...

$ pacman -Qqen > ~/arch_pkgs.txt

List of package not found in sync (e.g. AUR) ...

$ pacman -Qqem > ~/arch_foreign_pkgs.txt

If I ever need to re-install, or install these packages on another computer, simply run ...

$ sudo pacman -S --needed - < arch_pkgs.txt

2. Update package mirrors and upgrade

Generate a new list of package mirrors using reflector.

Example: Verbosely select the 5 most recently synchronized HTTPS mirrors located in either Canada or Germany, sort them by download speed, and overwrite the existing mirrorlist ...

$ sudo reflector --verbose --protocol https --latest 5 --sort rate --country Canada --country Germany --save /etc/pacman.d/mirrorlist

Perform a full system upgrade ...

$ sudo pacman -Syu

3. Search files from packages

pkgfile is a tool for searching files from packages in Arch's repositories.

Update the database by running ...

$ sudo pkgfile -u 

4. Clean package cache

Remove all cached versions of uninstalled packages ...

$ sudo paccache -ruk0

Delete all cached versions of installed packages, except for most recent 3 ...

$ sudo paccache -rv

5. Orphans and dropped packages

Remove packages that were installed as dependencies, but are no longer required by any installed package ...

$ sudo pacman -Qtd

6. Logs

Check for any failed systemd services ...

$ systemctl --failed

Check for errors in logfiles ...

$ sudo journalctl -p 3 -b

When pacman removes or upgrades a package, it sometimes creates copies of the config files with extensions *.pacnew and *.pacsave.

Check to see if any of these files are present and generate a log ...

$ sudo updatedb && locate --existing --regex "\.pac(new|save)$" > ~/pacnew.log

7. Script

Above commands are saved to my pinky shell script (Pinky is one of the four main ghosts in the Pac-Man series). I run the script once or twice a week to keep things humming.

Sources: pinky and arch_pkglist (generate package lists) and lib_homebin.sh (provide ascii colour codes for scripts)

Thanks for reading! Read other posts?

» Next: A(rch) to Z(ram): Install Arch Linux with (almost) full disk encryption and BTRFS

« Previous: Generate a list of installed Fedora packages on one device (and install on another)