How to Compile GNU Emacs from Source in Ubuntu 20.04 / 21.10

Last updated: December 27, 2021 — 1 Comment

For those hating the Flatpak and Snap packages, here’s how to compile GNU Emacs editor (v27.2 tested) from the source tarball while the Kevin Kelley’s PPA seems NOT to be updated anymore.

Before getting started, it’s recommended to remove old Emacs (if any) by running command in terminal (Ctrl+Alt+T):

sudo apt remove --autoremove emacs emacs-common

Install build dependencies:

Firstly, press Ctrl+Alt+T on keyboard to open a terminal window. When it opens, run command to install build-essential package:

sudo apt install build-essential

Next, search for and open ‘Software & Updates‘ from Activities overview screen. In the first tab, enable ‘Source code’ by ticking the checkbox.

Finally, refresh package cache and use apt build-dep command to install build depends:

sudo apt update && sudo apt build-dep emacs

Download Emacs source tarball:

The source tarball is available to download at the link below. So far the latest is ’emacs-27.2.tar.xz’:

Next, extract the tarball. Right-click on source folder and select ‘Open in Terminal‘ to open a terminal with that folder as working directory.

Build & Install Emacs:

After opening source folder in terminal, run script to generate configure scripts:


And, configure the source via command:


If no error outputs, build Emacs via command:

make bootstrap -j4

NOTE: here I use -j4 to start 4 threads to speed up make process. Depends on how many CPU cores in your machine, you may use -j8 or -j16 or just skip it.

When everything’s done successfully, install the editor via command:

sudo make install

Finally, try launching the app via emacs command.

Create app shortcut icon:

By default, it installs the executable binary as ‘/usr/local/bin/emacs‘. However, it does not create app icon for launching from start menu.

To create one, run command in terminal:

sudo gedit /usr/share/applications/emacs.desktop

It will create and opens the config file in Gedit text editor. When it opens, paste the following lines and save it.

[Desktop Entry]
Name=Emacs (GUI)
GenericName=Text Editor
Comment=GNU Emacs is an extensible, customizable text editor - and more
Exec=/usr/local/bin/emacs %F

Just like the package in Ubuntu repository, you may also create a shortcut icon for launching Emacs in command line:

sudo gedit /usr/share/applications/emacs-term.desktop

Paste the previous content but change the “Name“, “Exec” (use /usr/local/bin/emacs -nw %F instead), and set “Terminal = true”.

When everything’s done, search for and open ‘Emacs’ from Activities overview and enjoy!

How to Remove Emacs that compiled from source:

Until you removed the source folder, you may run command (open folder in terminal) in terminal from that folder to uninstall Emacs:

sudo make uninstall

If you’ve already removed the source. You may also re-download it, extract, open in terminal, and run the previous command to do the job.

And, remove the app shortcuts using command:

sudo rm /usr/share/applications/emacs*.desktop

That’s all. Enjoy!


I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee:

One response to How to Compile GNU Emacs from Source in Ubuntu 20.04 / 21.10

  1. If you intend to use emacs in daemon mode, use

    ./configure –with-x-toolkit=lucid

    to avoid an ongoing GTK+ bug that causes the Emacs client to crash.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 


This site uses Akismet to reduce spam. Learn how your comment data is processed.