source: handbook ch. 33, 51
Building packages
makepkg turns a PKGBUILD into an installable .pkg.tar.zst. This page walks through the full local workflow on an Arch-based host: toolchain setup, fetching PKGBUILDs, building, and testing the result. It assumes you already understand the PKGBUILD format from the reference.
Prerequisites
- An Arch-based host (Parch GNU/Linux or Arch Linux) with a current
pacman -Syu. - An unprivileged build user;
makepkgrefuses to run as root. - The packages below (root required to install them).
# pacman -S --needed base-devel pkgctl namcap pacman-contribbase-devel: gcc, make, and the rest of the compiler stack.pkgctl: devtools front end for cloning and chroot builds.namcap: PKGBUILD and package linter.pacman-contrib: providesupdpkgsumsandpactree.
Step by step
Create a build directory
Keep one directory per package, outside any repository checkout, so builds never interfere with your system files.
Working layout $ mkdir -p ~/builds/example-todo && cd ~/builds/example-todoGet a PKGBUILD
To study or rebuild an official package, clone its build recipe:
Clone an official PKGBUILD with pkgctl $ pkgctl repo clone linux-firmware $ cd linux-firmwareFor your own package, write the PKGBUILD in this directory instead. For software whose sources are covered in the application development section, you can package the same tree you develop in.
Check syntax and generate checksums
Validate before building $ bash -n PKGBUILD $ namcap PKGBUILD $ updpkgsums # fills or rewrites the sha256sums array in placeFetch sources only (optional)
To download and extract the sources without compiling, useful for inspecting what you are about to build:
Download and extract, no build $ makepkg -o $ ls src/After editing files under
src/, rebuild them withmakepkg -e, which reuses the existingsrc/tree instead of re-extracting and would otherwise discard your edits.Build the package
Full build with dependency installation $ makepkg -sOn success the directory contains
example-todo-1.4.2-1-x86_64.pkg.tar.zst.-sinstalls missing build dependencies via pacman; add-cto clean the work tree afterwards, or-sito also install the finished package immediately.Inspect the result
List what the package contains $ pacman -Qpl example-todo-1.4.2-1-x86_64.pkg.tar.zst $ namcap example-todo-1.4.2-1-x86_64.pkg.tar.zst
makepkg flags that matter
| Flag | Long form | Effect |
|---|---|---|
-s | --syncdeps | Install missing dependencies with pacman first. |
-i | --install | Install or upgrade the package after a successful build. |
-c | --clean | Remove leftover build files from the work tree. |
-o | --nobuild | Download and extract sources, then stop before build(). |
-e | --noextract | Do not extract sources, use what is already in src/. |
-g | --geninteg | Generate the integrity arrays and print them (prefer updpkgsums). |
-r | --rmdeps | Remove build dependencies after the build. |
-f | --force | Overwrite an existing package file of the same version. |
-R | --repackage | Re-run only package() on the previous build. |
-L | --log | Write the build output to a log file. |
-d | --nodeps | Skip dependency checks (escape hatch, use with care). |
--check | Run the check() function. | |
--packagelist | Print the package file names this PKGBUILD would produce. | |
--printsrcinfo | Print .SRCINFO to stdout. | |
--skippgpcheck | Skip source PGP verification. Only for sources you already trust. |
Test in a clean chroot
A host build succeeds with whatever happens to be installed on your machine. A clean chroot build proves the dependency lists are complete, which is exactly what reviewers and the build service will see. pkgctl build wraps devtools' makechrootpkg and manages the chroot for you:
$ cd ~/builds/example-todo
$ pkgctl buildIt builds the package inside a minimal container with only the declared depends, makedepends, and checkdepends installed, then drops the finished package next to the PKGBUILD. If the build fails there but succeeds on the host, your dependency arrays are incomplete or your build() reads something from the host that it should not. Rebuild the chroot from scratch with pkgctl build --clean after toolchain updates.
Sign packages with GPG
Signing lets others verify a package came from you:
$ gpg --full-generate-key
$ gpg --list-secret-keys --keyid-format=longCopy the long key ID (40 hex characters) into ~/.makepkg.conf:
PACKAGER="Your Name <you@example.com>"
GPGKEY="C4A91FF52A0B8E9A5C3D71F6B2E84D930FA7C612"With GPGKEY set, makepkg signs every package it produces. To sign or re-sign an existing file, run makepkg --sign. A detached signature appears next to the package as a .sig file.
Local test repository
For testing several packages together, index them into a local repository and point pacman at it:
$ mkdir -p ~/repo/x86_64
$ cp example-todo-1.4.2-1-x86_64.pkg.tar.zst ~/repo/x86_64/
$ repo-add ~/repo/x86_64/parch-local.db.tar.gz ~/repo/x86_64/*.pkg.tar.zstAdd the repository to /etc/pacman.conf (root required):
[parch-local]
SigLevel = Optional TrustAll
Server = file:///home/YOUR-USERNAME/repo/x86_64/Then # pacman -Syu example-todo installs from your local repo exactly the way users will install from world.
Troubleshooting
- Checksum mismatch: confirm the source change is legitimate upstream, then re-run
updpkgsums. Never blind-patch a mismatch; investigate first. - Builds on the host, fails in the chroot: a missing
makedependsentry or a hardcoded host path inbuild(). - makepkg refuses to run as root: run it as your normal user; pacman operations it triggers will ask for sudo.
- pacman cannot find the local package: re-run
repo-addafter copying new package files, the database is not scanned automatically.
Related pages
- PKGBUILD reference: variables and functions.
- Testing and validation: the full pre-submission test plan.
- Command reference: quick syntax for the tools used here.