Blog Home
Updated: 2022-04-07

Building Emacs 28 with Native Compilation on GNU/Linux

The upcoming release of Emacs version 28 is bring the addition of a just-in-time (JIT) native compiler for Emacs Lisp. This will allow for Emacs Lisp to seamlessly be compiled to machine code giving programs a 2-5times speed increase.

The following guide will walk through how to build Emacs with native compilation. Anyone with a basic understanding of the command line should be able to follow the steps.

Install the Build Dependencies

Since we are only focusing on native compilation we can just install the default build dependencies as specified by the distros package manager. This will save us time hunting down all necessary dependencies.

Debian, Trisquel, or Ubuntu

Install the libraries needed for building Emacs (build dependencies):

sudo apt-get build-dep emacs

Install libgccjit, the native compiler used by Emacs:

sudo apt-get install libgccjit0 libgccjit-10-dev

Fedora

Install the build dependencies for Emacs:

sudo dnf builddep emacs

Install libgccjit, the native compiler used by Emacs:

sudo dnf install libgccjit libgccjit-devel

Building Emacs

Currently the Emacs 28 pretest can be downloaded from the below link:

https://alpha.gnu.org/gnu/emacs/pretest/emacs-28.0.91.tar.xz

You can verify this file by following the instructions in the official release announcement. This will protect you from the file being corrupt or modified.

Extract the archive:

tar -xvf emacs-28.0.91.tar.xz

Move into the extracted directory and run the following build commands:

cd emacs-28.0.91
./autogen.sh
./configure --with-native-compilation

Verify the commands complete without errors otherwise you may be missing a dependencies. In addition, verify the below is output otherwise libgccjit is not properly installed.

Does Emacs have native lisp compiler?                   yes

If the above has completed correctly, then build Emacs by running make.

make

Try it out!

Once completed you should have a working Emacs 28 binary. You can run it manually and try it out.

./src/emacs

Run M-x version to check it is Emacs 28. Evaluate the following elisp to determine if you have native compilation setup correctly:

(native-comp-available-p)

That's it! Emacs should automatically start natively compiling all your installed packages in the background. You may receive some compiler warnings occasionally until this process has completed.

Installing

You can continue running it from the build directory or fully install it using make:

sudo make install

If at any point you'd like to remove it you can run:

sudo make uninstall

Comments:

Email questions, comments, and corrections to comment@taingram.org.

Submissions may appear publicly on this website, unless requested otherwise in your email.