Building Emacs 28.1 with Native Compilation on GNU/Linux
The recent release of Emacs version 28 brings 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
Verify your gcc version with gcc --version
, example output:
gcc (Debian 10.2.1-6) 10.2.1 20210110
Install the corresponding libgccjit of the same version.1 This is the JIT 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
You can download the official Emacs 28.1 source code from the below link:
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.1.tar.xz
Move into the extracted directory and run the following build commands:
cd emacs-28.1
./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
Footnotes:
Thanks to Pascal Jaeger and Răzvan Birișan for this correction.
Comments
Email comments and corrections to comment@taingram.org.
Submissions may be posted publicly unless requested otherwise in your email.