Skip to content

Arch Linux Pacman Hooks

Mattscreative edited this page Dec 5, 2025 · 2 revisions

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

  1. Understanding Hooks
  2. Creating Hooks
  3. Hook Examples
  4. Troubleshooting

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


This guide is based on the ArchWiki. For the most up-to-date information, always refer to the official ArchWiki.

Clone this wiki locally