I build Emacs from the release branch and install it as a package, so dpkg knows about every file and apt remove cleans it all up. For years I did that with checkinstall and one rule I never questioned: always pass --fstrans=no. This year it stopped working, so I found out why and switched to a tiny debian/ directory and dpkg-buildpackage.
Why checkinstall stopped working
checkinstall runs make install under installwatch, an LD_PRELOAD library that records every file touched, and packages whatever it saw.
Why --fstrans=no. By default, checkinstall redirects every write into a temporary folder (“filesystem translation”). make install puts the Lisp files in a folder named after the version, like share/emacs/31.1.90, and starts by deleting that folder with rm -rf. Under translation that delete fails:
rm: fts_read failed: No such file or directory
gzip: ../etc/publicsuffix.txt.gz already exists; not overwritten
**** Installation failed. Aborting package creation.
When you rebuild the same branch after a git pull, the version usually hasn’t changed, so that folder is already there from your last install, and that’s exactly when the default mode fails. --fstrans=no runs a real make install straight into /usr/local instead. checkinstall then becomes make install plus a list of the files it saw, so apt remove can clean them up later. It can only clean up what made it onto that list.
What broke. Debian’s checkinstall 1.8.3 (August 2026) made installwatch also log euidaccess() calls. bash makes one of those for every command it looks up in PATH. checkinstall’s filter only drops lines logged as access or unlink, so every program make install runs now lands in the package. Mine listed /usr/bin/bash, rm, sed, make and fifteen other system files, and dpkg refused it:
trying to overwrite '/usr/bin/bash', which is also in package bash
With --fstrans=no, everything had already been copied into /usr/local, so those files stayed there with no package owning them. --exclude=/usr/bin,/usr/share works around it.
A second trap. When you rebuild over an installed copy, share/emacs/site-lisp/subdirs.el and share/info/dir already exist and nothing writes them again. checkinstall doesn’t record them, so the new package doesn’t contain them, and dpkg deletes them during the upgrade. You have to apt remove the old package before every build.
If you’d rather stay with checkinstall, this works with 1.8.3:
sudo apt remove emacs-31
sudo checkinstall --fstrans=no --exclude=/usr/bin,/usr/share --nodoc --backup=no \
--install=no -y --pkgname=emacs-31 --pkgversion=31.1.90 make install
That was too many traps for me, so I switched to a real package.
What a .deb actually needs
Emacs’s Makefile supports DESTDIR, so make install DESTDIR=somewhere installs into a staging folder instead of your system. There’s nothing to trace, and the staging folder holds exactly what Emacs installs. debhelper (dh) builds the package around that: it configures, builds, installs into debian/emacs-31/, strips the binaries, and works out Depends: from the shared libraries Emacs actually links against.
Setup
You need debhelper and Emacs’s build dependencies. If you have deb-src lines enabled, apt build-dep emacs pulls in everything Debian’s own Emacs needs, which covers a pgtk build:
sudo apt install debhelper
sudo apt build-dep emacs
Work in your Emacs checkout. A fresh git clone has no configure script yet, so generate it once:
./autogen.sh
Keep the packaging out of your Emacs commits:
mkdir -p debian && echo debian/ >> .git/info/exclude
Read the version from configure.ac, and name the package after its major version, so the emacs-31 branch gives emacs-31 and a 32.x version gives emacs-32. The next steps use both variables, so stay in this shell:
VER=$(sed -n 's/^AC_INIT(\[GNU Emacs\], \[\([^]]*\)\].*/\1/p' configure.ac)
PKG=emacs-${VER%%.*}
The three files
debian/control describes the package. The EOF isn’t quoted here, so the shell fills in $PKG. The backslashes keep ${shlibs:Depends} and ${misc:Depends} for debhelper, which fills in the library dependencies there. Change the maintainer line to yours if you like; it’s only metadata here.
cat > debian/control <<EOF
Source: $PKG
Section: editors
Priority: optional
Maintainer: Your Name <you@example.com>
Build-Depends: debhelper-compat (= 13)
Package: $PKG
Architecture: any
Depends: \${shlibs:Depends}, \${misc:Depends}
Provides: emacs-from-source
Conflicts: emacs-from-source
Replaces: emacs-from-source
Description: GNU Emacs, local build from source
EOF
emacs-31 and emacs-32 install the same files, like /usr/local/bin/emacs, so only one can be installed at a time. The last three lines make apt handle that for you. Every emacs-NN package claims the same made-up name, emacs-from-source, and conflicts with anything else that claims it, so installing emacs-32 removes emacs-31 automatically. Debian uses the same pattern for mail servers.
I didn’t add Conflicts: emacs. Debian’s emacs-pgtk and friends Provides: emacs, so that line would make apt remove them. The two can live side by side: this package goes into /usr/local, Debian’s into /usr, and /usr/local/bin comes first in the default PATH.
debian/changelog sets the package version. The format is strict about spacing, so let the shell write it:
printf '%s (%s-1) unstable; urgency=medium\n\n * Local build.\n\n -- Your Name <you@example.com> %s\n' "$PKG" "$VER" "$(date -R)" > debian/changelog
debian/rules is a Makefile. dh $@ runs the standard sequence, and each override_dh_* target replaces one step. An empty override skips the step. Make normally wants a literal tab before every recipe line, which breaks easily when copying from a web page, so .RECIPEPREFIX swaps it for >.
cat > debian/rules <<'EOF'
#!/usr/bin/make -f
.RECIPEPREFIX = >
%:
> dh $@
override_dh_auto_configure:
> dh_auto_configure -- --with-pgtk --prefix=/usr/local
override_dh_autoreconf:
override_dh_update_autotools_config:
override_dh_shlibdeps:
> dh_shlibdeps -- --ignore-missing-info
override_dh_strip_nondeterminism:
override_dh_auto_test:
override_dh_usrlocal:
EOF
chmod +x debian/rules
Why each override is there
dh_auto_configure -- ...:dhpasses--prefix=/usrplus Debian’s usual flags first. Anything after--comes later, and configure uses the last--prefixit sees. Put your own configure options here.dh_autoreconf,dh_update_autotools_config: these regenerate the build system and replaceconfig.guessand friends. In a git checkout that rewrites tracked files underbuild-aux/.autogen.shalready producedconfigure, so skip both.dh_shlibdeps --ignore-missing-info: I have a hand-built tree-sitter in/usr/local/lib. No package owns it, sodpkg-shlibdepscan’t name a dependency for it and stops the build. This flag skips libraries it can’t map and still fills in the rest. If all your libraries come from apt, you can drop this override.dh_strip_nondeterminism: this one took real debugging. It rewrites every gzip file for reproducible builds, giving each.el.gza new timestamp. The sources then end up newer than their.elc. Withload-prefer-newerset tot, which many configs do, Emacs loads the compressed source instead of the bytecode during startup and fails withMissing 'lexical-binding' cookieand a void variable. Upstreammake installkeeps the original timestamps, which is why a plain install never had this problem.dh_auto_test: skipsmake check, which takes a long time.dh_usrlocal: Debian policy forbids packages from shipping files in/usr/localand this step enforces it. A package you build yourself can ignore that.
dh binary --no-act prints the steps it will run, without running them.
Build and install
dpkg-buildpackage -b -us -uc
-b builds only the binary package, and -us -uc skips signing. It starts with make distclean, so every build is a clean one, and you don’t need to run configure or make yourself. The .deb lands in the parent directory:
sudo apt install ../${PKG}_${VER}-1_amd64.deb
Check what landed outside /usr/local. This should print only the parent directories and changelog.Debian.gz under /usr/share/doc/emacs-31/, which debhelper adds to every package. Then see what it depends on:
dpkg -c ../${PKG}_${VER}-1_amd64.deb | grep -v ' \./usr/local/'
dpkg-deb -f ../${PKG}_${VER}-1_amd64.deb Depends
Removing it later is one command:
sudo apt remove emacs-31
It prints warnings like these, which used to bother me with checkinstall too:
dpkg: warning: while removing emacs-31, directory '/usr/local/share' not empty so not removed
They’re harmless, and you never see them with Debian’s own packages. dpkg only tries to delete a folder when the package being removed is the last one that lists it. Hundreds of packages list /usr/share, so removing curl says nothing. No official package lists /usr/local/share or /usr/local/lib, because Debian creates them with a script. That leaves emacs-31 as their only owner, so dpkg tries to delete them and warns when other files are still inside. After an upgrade where the version changed, you may also see unable to delete old directory '/usr/local/share/emacs/<old version>/...': Directory not empty. That means something dpkg doesn’t own is still in that folder, and you can delete it by hand.
Updating
After pulling new commits, refresh the package name and changelog, then rebuild:
git pull
VER=$(sed -n 's/^AC_INIT(\[GNU Emacs\], \[\([^]]*\)\].*/\1/p' configure.ac)
PKG=emacs-${VER%%.*}
sed -i "s/^\(Source\|Package\): .*/\1: $PKG/" debian/control
printf '%s (%s-1) unstable; urgency=medium\n\n * Local build.\n\n -- Your Name <you@example.com> %s\n' "$PKG" "$VER" "$(date -R)" > debian/changelog
dpkg-buildpackage -b -us -uc
sudo apt install ../${PKG}_${VER}-1_amd64.deb
If the major version changed, say from 31 to 32, apt removes emacs-31 and installs emacs-32 in one step. If the version didn’t change, apt reinstalls the package over itself. Unlike checkinstall, the package always contains the full install, so nothing goes missing. Remove old .deb files from the parent directory now and then.
Limits
This package is for the machine it was built on. It builds against whatever is installed there, /usr/local/lib included, and it skips everything Debian’s real Emacs packaging does: the split into emacs-bin-common, emacs-common and emacs-el, emacsen-common integration for elpa-* packages, and update-alternatives. To build something that works on any Debian machine, start from apt source emacs and build in a clean chroot with sbuild. For my own machine, three small files were enough.