Editing the Emacs source code using emacs.

Emacs is a text editor that was initially released in 1976. It is widely used by many who enjoy a programmable, moldable computing environment. A recent addition to Emacs brings improved performance using just-in-time compilation. This feature is referred to as native-compilation, and leverages the GCC compiler. This post will provide instructions for building emacs 28.1 on Ubuntu 20.04. The instructions should be very similar for any Debian-based distribution. For those interested in learning more about emacs and the technical details of the improvements, please refer to the links at the bottom of the post.

Open a shell and follow along with the commands below.

Enable Source Repositories.

# Become root.
$ sudo su -
$ sed -i '/deb-src/s/^# //' /etc/apt/sources.list && apt update
# Exit root.
$ exit 

Install dependencies

$ sudo apt -y install software-properties-common ca-certificates
$ sudo apt build-dep -y emacs
$ sudo apt install -y gcc-10
$ sudo apt install -y libgccjit0 libgccjit-10-dev libjansson4 libjansson-dev gnutls-bin
$ sudo apt install -y autoconf git make
$ sudo apt install -y libgtk-3-dev libwebkit2gtk-4.0-dev

Clone the emacs source code

$ git clone https://git.savannah.gnu.org/git/emacs.git
$ git checkout emacs-28.1

Build emacs

# Set your compiler.
$ export CC=/usr/bin/gcc-10
$ export CXX=/usr/bin/gcc-10
# Prepare the build
$ ./autogen.sh
$ ./configure --with-cairo --with-xwidgets --with-x-toolkit=gtk3 --with-native-compilation
# Build and install.
$ make -j$(proc)
$ sudo make install

Now you can start the application by running the command emacs in a terminal.

Further Reading