Skip to main content

Installing Emacs28 with Native compilation enabled

··4 mins·
Arch-Linux Macos Ubuntu Emacs
Makoto Morinaga
Author
Makoto Morinaga
A personal notebook for tech notes, coding, and system experiments.
Table of Contents

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
  2. Clone the Emacs repository
  3. 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, it is enabled.

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 disabled, 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!

Related

Elpy RPC Process and Python Version
··2 mins
Elpy Python Emacs
Installing yay on Arch Linux
··1 min
Arch-Linux Yay
Samba-based Time Machine Backup
··2 mins
Linux Macos Time-Machine Samba