Arch Linux Pacman Hooks - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Arch Linux Pacman Hooks Guide
Complete beginner-friendly guide to pacman hooks on Arch Linux, including creating hooks, hook types, and common hook examples.
Table of Contents
Understanding Hooks
What are Hooks?
Pacman hooks run scripts before/after package operations.
Hook types:
- Pre-transaction
- Post-transaction
- Pre-install
- Post-install
- Pre-remove
- Post-remove
Creating Hooks
Hook Location
Hook directory:
# System hooks
/etc/pacman.d/hooks/
# Create hook
sudo vim /etc/pacman.d/hooks/hook-name.hook
Hook Format
Hook structure:
[Trigger]
Operation = Upgrade
Type = Package
Target = package-name
[Action]
Description = Hook description
When = PostTransaction
Exec = /path/to/script
Hook Examples
Update GRUB
GRUB hook:
[Trigger]
Type = Package
Operation = Upgrade
Target = linux
[Action]
Description = Updating GRUB...
When = PostTransaction
Exec = /usr/bin/grub-mkconfig -o /boot/grub/grub.cfg
Rebuild Initramfs
Initramfs hook:
[Trigger]
Type = Package
Operation = Upgrade
Target = linux
[Action]
Description = Rebuilding initramfs...
When = PostTransaction
Exec = /usr/bin/mkinitcpio -P
Troubleshooting
Hook Not Running
Check hooks:
# List hooks
ls /etc/pacman.d/hooks/
# Test hook
sudo pacman -Syu
Summary
This guide covered pacman hooks, creation, and examples.
Next Steps
- Arch Linux Package Management - Package management
- Arch Linux System Configuration - System setup
- ArchWiki Pacman Hooks: https://wiki.archlinux.org/title/Pacman#Hooks
This guide is based on the ArchWiki. For the most up-to-date information, always refer to the official ArchWiki.