Building GNU Emacs from source

In the recent years, I've been configuring and building GNU Emacs from source, specifically the master branch of the emacs.git repository. Doing so allows me to use and test latest Emacs features, test my Emacs Lisp code with the laest developments in Emacs, and easily contribute my own changes to Emacs.

Before we start, I recommend reading the INSTALL file in the Emacs source repository for building Emacs from source tarballs, and also INSTALL.REPO for details about building Emacs from its source repository. The information provided here were built upon the details documented in those files. When in doubt, consult those files as the main, authoritative source of information for how to build Emacs from source.

Installing build dependencies

To build GNU Emacs from its source repository, we first need to install the various required tools and build dependencies of Emacs. On Debian-based systems, this can be done using apt. First, we need to add the source packages for the current release of our Debian-based distribution in apt's configuration by adding the corresponding deb-src lines in an apt source list file. For currently existing and older Debian releases, that would be done by adding a corresponding deb-src line for each deb line in /etc/apt/sources.list, such as:

deb http://deb.debian.org/debian/ trixie main
deb-src http://deb.debian.org/debian/ trixie main

In systems with recent apt versions with so-called modernized sources that might look editing a file like /etc/apt/sources.list.d/debian.sources and adding deb-src to the Types lines:

Types: deb deb-src
URIs: http://deb.debian.org/debian/
Suites: trixie
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Then run sudo apt update to have apt download package information from the configured sources.

We can now run sudo apt build-dep emacs to have apt download and install the build dependencies of Emacs. Debian-based distributions have packages for a few different configurations of Emacs, like emacs-pgtk with PGTK support for Wayland, and emacs-nox for Emacs without GUI support, which we can use with apt build-dep to download the specific dependencies of those configurations.

Cloning the Emacs source repository

After installing Git using sudo apt install git if not already installed, we're now ready to clone the Emacs source repository from GNU Savannah:

git clone https://https.git.savannah.gnu.org/git/emacs.git

We can add --depth 1 to make a shallow clone of the repository, if we don't care about having a complete log of previous commits to the Emacs repository (shallow clones are much faster).

If cloning over HTTPS is slow, we can try cloning over Git's own protocol (with the caveat that the repository is cloned over an insecure channel) or over SSH if we have a Savannah account, using one of the following URLs instead of the one above:

git://git.git.savannah.gnu.org/emacs.git
ssh://git.savannah.gnu.org/srv/git/emacs.git

Configuring the Emacs build

We now change to the Emacs repository directory we just cloned, and run the autogen.sh script once to generate the configure script, which we will use to configure Emacs to our liking:

cd emacs
./autogen.sh

To configure Emacs, the simplest approach is to run configure without any additional options, to have it use the defaults. We can get a list of available configuration options by running:

./configure --help

As I rebuild Emacs frequently, I normally don't "install" it, but for a typical setup, we'll want to specify the installation directory using --prefix, e.g.:

./configure --prefix=$HOME/.local

Later, make install will install Emacs under the specified directory.

By default, some of the files (such as *.el) will be compressed during installation. We can prevent that using --without-compress-install.

For my builds, I always use these configuration options:

--without-gconf
--without-gsettings
--without-gpm
--with-native-compilation

As I don't use the GNOME desktop, the GConf and GSettings integrations are always more trouble than useful for me, so I disable them. Further, I disable the GPM support, since I never use the mouse when using Emacs in the terminal. Lastly, I explicitly enable native compilation support.

In Wayland environments, I usually use PGTK:

--with-pgtk

And in X11 environments (e.g. EXWM), I either use the Lucid toolkit:

--with-x-toolkit=lucid --with-xaw3d

Or no toolkit at all:

--with-x-toolkit=no --without-xaw3d

Later after building Emacs, we can view the configuration options in Emacs by inspecting the system-configuration-options variable.

Building Emacs

After running ./configure, we can now finally build Emacs by running make. The first build will take a while, since all of Emacs is being built from scratch. Subsequent builds will generally be faster.

We can optionally run make install to install Emacs into the prefix specified earlier, or the default /usr/local. Note that this step might require using sudo if our user doesn't have write permission for the prefix.

Running Emacs

After building Emacs, we run it either from the install location if we ran make install earlier, or directly from the source repository. Currently, Emacs's build system makes a symlink to the latest built binary in the repository at src/emacs, and for emacsclient and other auxiliary binaries under the lib-src directory.

When skipping make install, we might still want to be able to easily launch Emacs from anywhere by typing emacs. We can do that by making symlinks to emacs and its auxiliary binaries inside a directory in our $PATH, such as $HOME/.local/bin, like so:

cd $HOME/.local/bin
ln -s $HOME/src/emacs/src/emacs .
for e in \
 ebrowse emacsclient etags make-docfile\
 make-fingerprint hexl rcs2log; do\
  ln -s $HOME/src/emacs/lib-src/$e .; done

For non-install setups like this, I augment Info-directory-list in my init file with the location of the info manuals in the repository to make them known to Emacs:

(defvar Info-directory-list) 
(with-eval-after-load 'info 
  (setq 
   Info-directory-list
   `(,@Info-directory-list
     ,(expand-file-name
       (convert-standard-filename "info/")
       source-directory)
     "/usr/share/info/"))) 

Updating Emacs

We can pull in the latest changes in the Emacs repository using git pull, then rebuild our Emacs by running make.

Occasionally, rebuilds may fail due to bad interaction of changes with leftover build artifacts. In such cases, the easiest thing to do would be a make bootstrap for an almost-from-scratch build. On even rarer occasions, make bootstrap might also fail. We would then want to run git clean -xdf to remove every file that's not tracked by Git, as if we freshly cloned the repository. In such cases, we would need to configure the build again using ./configure and provide the desired options before running make again.

Further reading

Protesilaos's similar post from early 2025 was part of the inspiration for writing and sharing my version:

https://protesilaos.com/codelog/2025-03-22-emacs-build-source-debian/

Lastly, to reiterate, Emacs's own INSTALL and INSTALL.REPO files for building from source:

https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/INSTALL
https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/INSTALL.REPO

Take care, and so long for now.