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.

How-to

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):

./src/emacs

To open Emacs in terminal mode (“-nw” is the short form for the option “–no-window-system”):

./src/emacs -nw

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).

Casual use of Emacs

Use as a secondary text editor to see two parts of a document at the same time

For instance, on a two-monitor system, Emacs on one screen and Geany on the other.

This useful as Geany is not that great with more than one view per document.

Menu Buffers*scratch*.

Paste

Emacs, by default, uses the nonstandard keyboard shortcut Ctrl + Y to paste into a document from the system clipboard (the standard is Ctrl + V).

Copy

Emacs, by default, uses the nonstandard keyboard shortcut Alt + W to copy to the system clipboard (the standard is Ctrl + C).

It is also nonstandard in that it removes the selection after copy.

Word wrap

The default is to wrap words for long lines. This is not normally desirable.

To change it for the current document (will not be permanent): Alt + X toggle-truncate-lines (tab completion works – there isn’t any need to type all of “toggle-truncate-lines”).

To change it permanently:

vi ~/.emacs

Add this line (yes, only one single quote):

(set-default 'truncate-lines t)

Search in the current document

Emacs, by default, uses the nonstandard keyboard shortcut Ctrl + S to search in the current document (the standard is Ctrl + F). Use Ctrl + R to search backward.

A subsequent Ctrl + S works as search next (the standard is F3).

Use Alt + C to toggle case-sensitivity.

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.

‘apt-get’ blues

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

Result:

libtiff-dev - Tag Image File Format library (TIFF), development files
libtiff5-dev - Tag Image File Format library (TIFF), development files (transitional package)

Leave a Reply

Your email address will not be published. Required fields are marked *

*