How to Build Emacs on Linux

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

This page shows you how to compile/build latest version of publically released version of emacs on Linux. It should work for building any emacs version. I assume you are on Ubuntu Linux.

If you want to build latest development version, see: How to Build Emacs from git Repository.

Summary

Here's 3 minutes summary of what to do.

① Install essential build tools and dependency first:

# install essential build tools
sudo apt-get install build-essential

② Download emacs dependencies:

# get all dependencies of a previous emacs version
sudo apt-get build-dep emacs23

③ Download emacs source code from http://ftp.gnu.org/gnu/emacs/, then cd to the emacs source directory.

④ Compile emacs:

cd ‹source dir name›
./configure
make
sudo make install # optional. This basically copy the binary to /usr/local/bin

Following is more detailed explanation.

Check Prepared Emacs Packages

On Ubuntu, typically you install by sudo apt-get install emacs24, where the “emacs24” may be other version.

To search for emacs, do: apt-cache search emacs | grep emacs.

When emacs has a new version, Ubuntu Linux typically takes half a year to a year to have a prepared package.

Or, you build it yourself. It's easy.

Download Emacs Source Code

Download emacs source code here: http://ftp.gnu.org/gnu/emacs/

Compile Steps

To compile programs on unix, typically the steps are:

cd ‹source dir name›
./configure
make
sudo make install # optional. This basically copy the binary to /usr/local/bin

In the source dir, there's usually a README or INSTALL file.

However, you'll probably fail in the configure step, because emacs requires lots other libraries, also, you might be missing build tools.

Here's some sample output of failure:

checking for libXaw... configure: error: No X toolkit could be found.
If you are sure you want Emacs compiled without an X toolkit, pass
  --with-x-toolkit=no
to configure.  Otherwise, install the development libraries for the toolkit
that you want to use (⁖ Gtk+) and re-run configure.
configure: error: The following required libraries were not found:
    libXpm libjpeg libpng libgif/libungif libtiff
Maybe some development libraries/packages are missing?
If you don't want to link with them give
    --with-xpm=no --with-jpeg=no --with-png=no --with-gif=no --with-tiff=no
as options to configure
configure: error: The required function `tputs' was not found in any library.
These libraries were tried: libncurses, libterminfo, libtermcap, libcurses.
Please try installing whichever of these libraries is most appropriate
for your system, together with its header files.
For example, a libncurses-dev(el) or similar package.

You can type ./configure --help to see the options it supports. See its output here: linux_compile_emacs_24_config_help_output.txt.

Install Basic Build Tools

If you haven't done so already, do: sudo apt-get install build-essential. This will install many tools for building.

To see info about the package, do apt-cache showpkg build-essential and apt-cache show build-essential.

Dependencies

You'll need to install some 30 dependent libraries. The trick is to know which are they. Took me a couple hours to find out the hard way.

The easiest way is to install all dependencies of a previous version of the package, like this:

sudo apt-get build-dep emacs23

This will install all packages emacs23 depends on. Here's the output on my machine:

The following NEW packages will be installed:
  autoconf automake autotools-dev bsd-mailx diffstat imagemagick libasound2-dev libdatrie-dev
  libdbus-1-dev libgconf2-dev libgpm-dev libgtk2.0-dev liblockfile-dev liblqr-1-0 libm17n-dev
  libmagickcore3 libmagickwand3 libncurses5-dev libotf-dev librsvg2-dev libthai-dev libtinfo-dev
  libxml2-dev postfix quilt sharutils texinfo xaw3dg xaw3dg-dev xutils-dev
0 upgraded, 30 newly installed, 0 to remove and 4 not upgraded.
Need to get 12.4 MB of archives.
After this operation, 49.5 MB of additional disk space will be used.

You can see the full bash output here: linux_compile_emacs_23_dependencies.txt

config, make

make distclean to clear files created by configure.

Once you have all the dependencies, you can now run ./configure and make again.

Here's a sample successful output:

After successful “make”, you should have a binary at src/emacs in the current dir. You can test run it by src/emacs &.

Optionally, you can do sudo make install, which will basically copy the binary to /user/loca/bin/, and copy various elisp files, info files, man pages, etc, into various Linux default dirs.

Thanks to Mike Oliver, Christian Lynbech, daniël bosold for inputs.

Like it?
Buy Xah Emacs Tutorial
or share
blog comments powered by Disqus