Installing Emacs28 with Native compilation enabled

Apr 27, 2022 Dec 11, 2023

Hello. I see that Emacs 28.1 has been released. Various new features have been introduced, but I am still interested in the Native Compilation feature that makes Emacs faster.

So, in this article, I will personally summarize how to install Emacs28 with Native compilation enabled on Ubuntu, Arch Linux, and macOS.

Basic flow

The installation of Emacs28 with Native compilation enabled is carried out in the following flow.

  1. install libgccjit library and other libraries required to build Emacs28

The libgccjit library is required to enable native compilation.

  1. clone the Emacs repository
  2. build Emacs28

I will install Emacs28 on Ubuntu, Arch Linux, and macOS.

Ubuntu

Install necessary libraries

Install the libraries required to build Emacs28 with the following command. There are several versions of libgccjit, so change accordingly. I used libgccjit-12-dev.

terminal
sudo apt install autoconf make texinfo gnutls-bin libgccjit-12-dev

Clone the Emacs repository

Clone the Emacs repository with the following command. Since I only want to build Emacs28, clone only the necessary files with the --depth 1 --branch emacs-28 option.

terminal
git clone --depth 1 --branch emacs-28 git://git.savannah.gnu.org/emacs.git

Building Emacs28

First, go to the repository and run autogen.sh to create a configure file.

terminal
cd ./emacs
./autogen.sh

Next, give yourself the necessary options and run configure. The option --with-native-compilation enables native compilation. Other options can be given according to your personal preference and environment. I set --with-x=no because I do not need a GUI environment.

Note that the path to libgccjit is passed to configure in CFLAGS, but be aware that the path may change slightly depending on the version of libgccjit installed.

terminal
CFLAGS='-I/usr/lib/gcc/x86_64-linux-gnu/12/include -L/usr/lib/gcc/x86_64-linux-gnu/12' ./configure --prefix=/usr/local --with-native-compilation --with-x=no --with-gnutls=ifavailable --without-pop

When configure has been successfully run, run make and make install at the end.

terminal
make
sudo make install

This completes the installation on Ubuntu.

Arch Linux

On Arch Linux, we can install Emacs with Native compilation enabled by pacman -S emacs-nativecomp. However, since the GUI version is installed, GUI libraries such as gtk are also installed. Since I do not need GUI libraries such as gtk and use Emacs only in the terminal, I build Emacs without GUI functions by the following procedure.

Install necessary libraries

Install the libraries required to build Emacs28 with the following command.

terminal
sudo pacman -S libgccjit

There are other libraries required for the build in addition to the above, but I forgot what I installed, so I will skip them this time. If any libraries are missing, an error will be displayed at build time, so install them accordingly.

Clone the Emacs repository

Clone the Emacs repository with the following command. Since I only want to build Emacs28, clone only the necessary files with the --depth 1 --branch emacs-28 option.

terminal
git clone --depth 1 --branch emacs-28 git://git.savannah.gnu.org/emacs.git

Building Emacs28

First, go to the repository and run autogen.sh to create a configure file.

terminal
cd ./emacs
./autogen.sh

Next, run configure with the necessary options. The option --with-native-compilation enables native compilation. Other options can be given according to your personal preference and environment. I use --with-x=no because I don’t need a GUI environment.

terminal
./configure --prefix=/usr/local --with-native-compilation --with-x=no --with-gnutls=ifavailable --without-pop

When configure has been successfully run, run make and make install at the end.

terminal
make
sudo make install

This completes the installation on Arch Linux.

macOS version

I use Homebrew on macOS, so install Emacs28 with Native compilation enabled on Homebrew.

You can install it using the formulas in Emacs Plus and follow the instructions.

terminal
brew tap d12frosted/emacs-plus
brew install emacs-plus@28 --with-native-comp

Confirmation

Check that Native compilation is enabled in Emacs28 after the build is complete.

Start Emacs and run M-x describe-variable RET system-configuration-features RET. If Its value is contains NATIVE_COMP as shown in the following image, it is enabled.

HELP

End

I’m glad to see that the areas I was concerned about have been speeded up. I have not compared it with the version with Native compilation enabled, so I think some parts have been speeded up just by switching to Emacs28. But I am delighted with the overall speedup, especially in the lsp-mode operation.

If you have not yet used Emacs28 with Native compilation enabled, please give it a try!

Posted by mako
Related Posts
No related posts
Comment
...