iBoyko - "sort of" a website

# How to Compile and Build the Latest Emacs 29 from Scratch on Ubuntu 20.04

## Building latest Emacs on Ubuntu is not difficult. Learn how to do it.

Posted by Yakov Boyko on November 10, 2021

Let's try building a GUI Emacs (version 29, unreleased, at the time of this writing) by compiling the source code. Version 28+ of Emacs is attractive because it includes compilation of elisp code to native code, which drastically speeds up the execution. At the time of this writing, this feature has not been included in the official Emacs releases. Hence, the need to compile the code from scratch to get a working Emacs that is fast. For more information, see here.

First, clone the repository

git clone --depth 1 git://git.savannah.gnu.org/emacs.git
cd emacs


The next step is to install a few tools needed to compile the source code. A rough list for the first try is as follows:

sudo apt-get install -y stow build-essential libx11-dev xaw3dg-dev \
libjpeg-dev libpng12-dev libgif-dev libtiff4-dev libncurses5-dev \
libxft-dev librsvg2-dev libmagickcore-dev libmagick++-dev \
libxml2-dev libgpm-dev libghc-gconf-dev libotf-dev libm17n-dev \
libgnutls-dev


If there is an issue during the next couple of steps, it is most likely to be resolved by updating or installing some additional libraries. Each system is slightly different, and it is impossible to predict what will be needed ahead of time.

You will need to set a couple of flags prior to the build. These flags should suffice. However, in some cases, more are needed. Run the following code at command line. We are specifying where the compilers are on your system.

export CC=/usr/bin/gcc-10 CXX=/usr/bin/gcc-10


Run the auto generation step.

./autogen.sh


Then, run the configuration. The example we are giving provides a version of Emacs that is quite stacked with features. Your needs may vary. In either case, this example includes the flag, which will provide the native compilation of code and allow Emacs to execute and run faster. If you get errors during the configuration, they need to be resolved before you can proceed. In 99% of the cases, the resolution comes down to either updating or installing additional packages on your system. These are tools which are required to build the package from scratch.

./configure --with-mailutils --with-native-compilation --with-xwidgets --with-modules --with-native-compilation --with-gnutls --with-jpeg --with-png --with-rsvg --with-tiff --with-wide-int --with-xft --with-xml2 --with-xpm


Then, proceed with making of the package. In my case, I am allocating 16 cores to running this job. On AMD Ryzen 5800X it takes a few minutes of time.

make -j16


If there are no errors, you can proceed with installing the newly built package into your system. If there are older versions of Emacs installed, it may be prudent to remove them at this point.

sudo apt remove emacs


Now, install the new Emacs. The following command will both check the results and install the new package.

sudo checkinstall