Installing latest Emacs on Termux

Table of Contents

Termux is an Android application available through F-Droid which creates a terminal emulator which can run Emacs.

Termux comes with Emacs 28.1 (without native compilation) and it can be installed with pkg install emacs.

The github repo termux-packages includes the build directions and patches needed in order to get Emacs working on an Android phone.

In order to get the latest Emacs built from source (29.0), clone the termux-packages repository and use:


to enter a docker container build environment. Edit the folder packages/emacs/ as follows:

Ensuring a smooth build

Build the Emacs package once before making edits with ./build-package.sh -I emacs. This will download all dependencies for Emacs, then build Emacs. It will take quite a long time.

Getting the source code

I will be using the Github mirror of Emacs which has a direct download url feature. Copy the full SHA of the latest commit and, in a new terminal, clone the source code for Emacs as a sibling of termux-packages.

mkdir emacs
cd emacs
git init
git remote add origin https://github.com/emacs-mirror/emacs.git
git fetch --depth 1 origin <commit-hash>
git checkout FETCH_HEAD

Next, generate a hash for the Emacs source code using sha256sum:

wget -O - https://github.com/emacs-mirror/emacs/archive/<commit-hash>.zip | sha256sum

In the file packages/emacs/build.sh, change TERMUX_PKG_SRCURL to point at the Emacs mirror on github, and TERMUX_PKG_SHA256 to value generated above:

TERMUX_PKG_SHA256=<sha256sum output>

Apply patches

One by one, check each patch file in packages/emacs by applying it to the Emacs source code. Assuming the Emacs source code and termux-packages are in the same directory:

cd emacs
git apply ../termux-packages/packages/emacs/Makefile.patch

If it returns an error, make the changes specified in the patch file manually, then recreate the patch file:

git diff > ../termux-packages/packages/emacs/Makefile.patch
git stash -m "Termux Makefile patch"

Building again

Once all the patches can be applied to the master branch of Emacs, run ./build-package.sh -I emacs again. Exit the docker container, and copy the generated file output/emacs_29.0-1_aarch64.deb to your Termux home directory. From within termux, run:

pkg install ./emacs_29.0-1_aarch64.deb

To install the latest Emacs. This may result in an error like:

mv: cannot stat '/data/data/com.termux/files/usr/bin/emacs*.pdmp': No such file or directory

In order to resolve this, I manually ran the postinst steps in the packages/emacs/build.sh file from within Termux.

export TERMUX_PKG_VERSION=29.0.50
export TERMUX_ARCH=aarch64

cd $PREFIX/share/emacs/$TERMUX_PKG_VERSION/lisp
LC_ALL=C $PREFIX/bin/emacs -batch -l loadup --temacs=pdump
mv $PREFIX/bin/emacs*.pdmp $PREFIX/libexec/emacs/$TERMUX_PKG_VERSION/${TERMUX_ARCH}-linux-android*/