Building Emacs from source on Ubuntu 20.04 in 2020
Using the package manager in Ubuntu to install Emacs will result in some older version (version 26.3 on Ubuntu MATE 20.04 (Focal Fossa)). One way to get the latest version, currently 27.2 for the stable version, is to compile from source.
Most blog posts and Stack Exchange answers about this are out of date. The versions of the required packages to install in order for the compile to succeed are wrong and the set of packages is different.
The main part of this blog post is step-by-step instructions on how to compile the latest version of Emacs from source. The gist is to install the latest (or available) development edition (suffix “-dev” in the package name) of the dependencies for Emacs. Development here means a package includes the header files (.h, etc.) – required for the build from source (that is, they are not pre-alpha versions (unstable/buggy)).
But it also covers all the error messages one will run into if following the instructions on the official Emacs website (they do not work at all on Ubuntu – or rather there are a lot of required prerequisites). Or it can be useful for getting this to work in the future, including new versions of Ubuntu or other Linux distributions.
In Bash (terminal window):
1. Get the source code (the work folder is off in sub folder ‘temp2/2020-11-10’ from the current user’s home folder):
mkdir ~/temp2 mkdir ~/temp2/2020-11-10 cd ~/temp2/2020-11-10 wget http://ftp.download-by.net/gnu/gnu/emacs/emacs-27.1.tar.gz wget http://ftp.download-by.net/gnu/gnu/emacs/emacs-27.1.tar.gz.sig tar -zxvf emacs-27.1.tar.gz
2. Install package ‘libtiff-dev’ first (separately from the following installs):
sudo apt-get install libtiff-dev
3. Next, install more packages and compile Emacs
sudo apt-get install build-essential sudo apt-get install libgtk-3-dev libtiff5-dev libgif-dev libjpeg-dev libpng-dev libxpm-dev libncurses-dev cd ~/temp2/2020-11-10/emacs-27.1 ./configure --with-gnutls=ifavailable make
At this point, Emacs can be launched (this will open a GUI application):
To open Emacs in terminal mode (“-nw” is the short form for the option “–no-window-system”):
Exit by Ctrl + X, Ctrl + C (or F10, arrow up, and Enter to invoke the menu, select the last menu command in the first menu (“Quit”)).
It can now be installed (optional):
sudo make install
After this, it will launch the new version (27.1) anywhere on the command line (but the one in the GUI system (e.g., Win + “emacs”) will still list the old version).
Appendix A Error messages and troubleshooting
While the main part of this post is focused on getting Emacs compiled as quickly as possible, this appendix documents the error messages that you may run into.
Search in the list of all packages (not just the installed ones) to get the package names for the available development versions of libtiff:
apt-cache search libtiff | grep -i dev
libtiff-dev - Tag Image File Format library (TIFF), development files libtiff5-dev - Tag Image File Format library (TIFF), development files (transitional package)