-
-
Notifications
You must be signed in to change notification settings - Fork 2
Arch Linux Pacman Hooks
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to pacman hooks on Arch Linux, including creating hooks, hook types, and common hook examples.
Pacman hooks run scripts before/after package operations.
Hook types:
- Pre-transaction
- Post-transaction
- Pre-install
- Post-install
- Pre-remove
- Post-remove
Hook directory:
# System hooks
/etc/pacman.d/hooks/
# Create hook
sudo vim /etc/pacman.d/hooks/hook-name.hookHook structure:
[Trigger]
Operation = Upgrade
Type = Package
Target = package-name
[Action]
Description = Hook description
When = PostTransaction
Exec = /path/to/scriptGRUB hook:
[Trigger]
Type = Package
Operation = Upgrade
Target = linux
[Action]
Description = Updating GRUB...
When = PostTransaction
Exec = /usr/bin/grub-mkconfig -o /boot/grub/grub.cfgInitramfs hook:
[Trigger]
Type = Package
Operation = Upgrade
Target = linux
[Action]
Description = Rebuilding initramfs...
When = PostTransaction
Exec = /usr/bin/mkinitcpio -PCheck hooks:
# List hooks
ls /etc/pacman.d/hooks/
# Test hook
sudo pacman -SyuThis guide covered pacman hooks, creation, and examples.
- 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.