Compiling Emacs Master Branch from source on Ubuntu
Compiling Emacs from source is non-trivial. Here are the steps for the interested reader:
Get the source-code
git clone git://git.sv.gnu.org/emacs
This step takes a long time, because the Emacs source repository is giant. But I recommend cloning the full repo:
- It's easy to stay updated with the latest changes with
git fetch
in the future. - Telling Emacs where the C source code is let's us jump all the way down into primitive functions when exploring elisp functions.
(setq source-directory (expand-file-name "/<path>/emacs/")) (setq find-function-C-source-directory (expand-file-name "/<path>/emacs/src/"))
Make sure you have the all the dependencies installed
The easiest way to install almost all the dependencies is to run the following command:
sudo apt build-dep emacs
This command uses the information in the Ubuntu package management system. In my experience today (libgccjit
and libtree-sitter
. Let's install those now:
Installing libgccjit
- Check your gcc version with
gcc --version
. - You need to install
libgccjit-<x>-dev
where<x>
is your gcc version.sudo apt install libgccjit-11-dev
Installing libtree-sitter
sudo apt install libtree-sitter-dev
Compile Emacs!
# Generate Configure and Make scripts:
./autogen.sh
# Run the Configure command:
./configure --without-toolkit-scroll-bars --with-x-toolkit=gtk3 --with-xpm=ifavailable --with-jpeg=ifavailable --with-gif=ifavailable --with-tiff=ifavailable --with-xml2 --with-rsvg --without-pop --with-png --with-mailutils --with-native-compilation --with-cairo --with-harfbuzz --with-tree-sitter --with-sqlite3
# If everything works:
make -j8 bootstrap
# If everything works:
make -j8
# Test the binary:
src/emacs -Q
# Install the binary:
sudo make install
Misc notes
- Running
./configure
will output the default flags that Emacs plans to use.- If you look at the last section of what
configure
prints, you can check if there are new options which are not covered by my configure command above.
- If you look at the last section of what
- To restart compilation from an absolutely clean slate, run
make distclean
- To know the max number of cores you can run parallel compilation on, run
nproc
. This is the max value for thej
parameter in themake
command.
Published On: Wed, 01 Jan 2025.