Pacman

How to use the Pacman package manager and fix common errors




Upgrading packages

pacman -Syu

Uninstall packages

pacman -Rscn

Remove orphaned packages

pacman -Qtdq | pacman -Rns -

Remove all the cached packages that are not currently installed, and the unused sync database

pacman -Sc

To remove all files from the cache, use the clean switch twice, this is the most aggressive approach and will leave nothing in the cache folder

pacman -Scc

Create a hook to remove cached packages automatically after every pacman transaction

pacman -Syu pacman-contrib
/etc/pacman.d/hooks/90-remove-cache.hook
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Cleaning the package cache...
When = PostTransaction
Exec = /usr/bin/paccache -rvk2

List files installed by a package

pacman -Ql

Force remove package

pacman -Rdd

Downgrade package

pacman -U /var/cache/pacman/pkg/NAME

Update your archlinux-keyring before upgrading your system

pacman -Sy archlinux-keyring && pacman -Su

Skip a specific package when upgrading the system

pacman -Syu --ignore=PACKAGE

Error: failed to commit transaction (conflicting files)

pacman -Syu PACKAGE --overwrite FILEPATH

Error: unable to lock database

rm /var/lib/pacman/db.lck

Create list of installed packages

pacman -Qqen > pkglist
pacman --overwrite -S $(< pkglist
pacman -Qqdn > pkglist_deps
pacman --overwrite --asdeps -S $(< pkglist_deps

Script to update the system

~/bin/update
#!/bin/bash
sudo /root/bin/update
chmod 700 ~/bin/update

/root/bin/update
#!/bin/bash
GREEN='\033[0;32m'
echo -e "${GREEN}Updating keyring" &&
pacman -Sy archlinux-keyring --noconfirm &&
echo -e "${GREEN}Running pacman updates" &&
pacman -Syu --noconfirm &&
echo -e "${GREEN}Running AUR updates" &&
sudo -u wildw1ng yay -Syu --devel --needed --removemake --noconfirm --answerclean All --answerdiff None &&
echo -e "${GREEN}Checking for orphans and dropped packages" &&
pacman -Qdt
pacman -Qtdq | pacman -Rscn -

echo -e "${GREEN}System is up to date"
PS3="Please select an option: "
options=(reboot shutdown continue)
select menu in "${options[@]}";
do
  echo -e "\nyou picked $menu ($REPLY)"
  if [[ $menu == "reboot" ]]; then
    reboot; break;
  elif [[ $menu == "shutdown" ]]; then
    shutdown now The system is going down for required maintenance. Please save any important work you are doing now!; break;
  else
    break;
  fi
done
chmod 700 /root/bin/update