How to install a usable Emacs in Android (Feb 2014)

Emacs logo. Since I mentioned in a review that I’m using Emacs on my Android Nexus 7 tablet, I’ve received several requests for information about how I set it up. There is a prepackaged Emacs app in the Google Play store, but it does not work as distributed, because it bundles a broken terminal application. The Emacs binary itself is fine, though, and with a bit of manual work, you can install it to run inside a different terminal application (I use Terminal IDE below).

Note: Emacs needs a full-featured PC-style keyboard. I usually run Emacs on my tablet with an external Bluetooth keyboard; if you want to use a soft keyboard, consider installing the Hacker’s Keyboard, which has all of the modifier keys Emacs expects.

Request: Would anyone be willing to rebundle Emacs in an easily-installable form for Terminal IDE, and make this blog posting obsolete?

Installing Emacs for Terminal IDE

  1. Install the Terminal IDE app on your Android device.

  2. In your Android browser, go to http://emacs.zielm.com/data/ and download the files emacs.lzma, etc.tlzma, and lisp.tlzma, then copy them to your Terminal IDE home directory.

  3. Launch a shell in Terminal IDE and run the following commands:

    $ unlzma emacs.lzma
    $ chmod 755 emacs
  4. At this point, you should already be able to run emacs by typing

    $ ./emacs

    (though it will fail because it can’t find its etc directory). If you want, just put it somewhere on your executable path, like you would in any Linux installation.

  5. Create a directory /sdcard/emacs/ (or make it somewhere different, if you’re willing to set environment variables to tell Emacs to look somewhere else).

  6. Copy the downloaded files etc.tlzma and lisp.tlzma to /sdcard/emacs/etc.tar.lzma and /sdcard/emacs/lisp.tar.tzlma

  7. Change to the /sdcard/emacs/ directory and run the following commands:

    $ unlzma etc.tar.lzma
    $ tar xvf etc.tar
    $ unlzma lisp.tar.lzma
    $ tar xvf lisp.tar
  8. Test that emacs starts up OK now (run from wherever you installed the binary):

    $ ~/emacs
  9. If all is well, you can optionally delete the tar files to save space:

    $ rm /sdcard/emacs/etc.tar /sdcard/emacs/lisp.tar
  10. Enjoy Emacs in Android! You might consider doing an C-u 0 M-x byte-recompile-directory on /sdcard/emacs/lisp/ (and any other lisp directories) to make sure you’re up to date.

About David Megginson

Scholar, tech guy, Canuck, open-source/data/information zealot, urban pedestrian, language geek, tea drinker, pater familias, red tory, amateur musician, private pilot.
This entry was posted in General. Bookmark the permalink.

21 Responses to How to install a usable Emacs in Android (Feb 2014)

  1. Gena Hahn says:

    Wonderful. So now I will be interested in an Android tablet. Anyone know if a version of miktex exists (will exist) for android to complete what many of us need?

    • It should be possible to compile from source in Android via Terminal IDE (which includes gcc), but you’ll probably have to work around a lot of issues with where executables are stored, compile some libraries, etc. Cross-compiling from a Linux laptop will probably be easier (though I haven’t tried setting up a cross-compilation environment).

  2. kblee says:

    I followed the instruction, but at the end, it says “Permission denied”.
    I even did chmod as a root. Still it says “can’t execute: Permission denied”

  3. kblee says:

    I didn’t know you can just rename them. It works perfectly!
    Thanks so much. My life will be different now….

  4. Would you be willing to write a shell script which can be run from Terminal-IDE which will install/upgrade emacs in that environment?

  5. bobdc says:

    Hi Dave! Long time no… anyway, thanks so much for this. Every step worked great on my LG G Pad. While I’m in Emacs, it’s not recognizing Ctrl+Space yet, but I’m sure there’s some configuration file I have to fiddle with somewhere.

    For my next step, I don’t know whether to put nxml on it or to try this with my S3 phone. Emacs on my phone!

  6. Keishiko says:

    Hi. Thank you for sharing this. I was able to follow every instruction you gave, then when I tried ~/emacs, I got “Loading emacs-lisp/byte-run (compiled; note, source file is newer)…” Nothing happens after waiting for quite sometime that’s why I terminated Terminal IDE. What should I do? Thank you and more power!

  7. Emmanuel Charpentier says:

    I’d love to have this on my phone (not for heavy work, but to have some usable text editor to review latex file I happen to have on the phone..). I tried the prepackaged version : was a pain in the ass (insisted to run in lanscape mode, which is an exruciating pain somewhere on a phone…) then uninstalled it.

    Then installed Terminal IDE (went fine) then followed your instructions. This hangs at the launch of ~/emacs : clears screen (except for softkeyboard), maints a line of dashes in the all-but-las line of the (usable part of the) screen, displays “using loadpath (/sdcard/emacs/lisp) n the last line (the cursor is right after the closing paren) an hangs … indefinitely.

    Trying to close terminal emulator does not succeds : even after wiping it from the task list, a second consultation of the task list shows it back again. Trying to shutdown all terminals does not succeed either. The only way I found to get rid of it is to reboot the phone.

    Any suggestion ? Note : I’m totally ignorant of java and Android : my background is Unix, C, Lisp and R ; I might be a little bit out of my depth here…

  8. I’ve tried recently using the Emacs app from the Play Store, but the software couldn’t be downloaded because http://emacs.zielm.com/ can’t be resolved.

    Anyway, I believe that compiling Emacs against the Android environment (to get the paths correct for an app, and correct library links) and running it from inside a nice terminal in Android is no big conceptual problem. So I might try to do this some time to get an Emacs working even in an unrooted Android.

    As for a rooted Android, it has been long known that it is possible to install a GNU/Linux distro into a chroot.

    But out of interest, I was also interested to get a running Emacs in an unrooted Android.

    As a faster solution (without recompiling Emacs against the Android environment), I’ve used the GNURoot app (with GNURoot Wheezy) which allows to use a GNU/Linux distro like Debian in an unrooted Android. There I could start Emacs, as well as ssh to my computers, and hopefully I’ll be able to use TRAMP, too. (I haven’t yet tried this out.)

    The GNURoot app does all this by means of a [“PTRACE container”](http://unix.stackexchange.com/a/9188/4319) implemented by [“proot”](http://proot.me/): interception of syscalls and “emulating” what should be done in the different Android and unprivileged environment. (Redirecting paths, faking the root user privileges, etc.)

    [It was a while ago when I learned about such projects](https://groups.google.com/d/msg/proot_me/h3rDV8na9kc/4mSCyOsX28UJ).

    It’s a pity that source code for GNURoot](https://github.com/corbinlc/gnuroot) seems not to be well documented, so it’s not easy to start hacking with it right away or at least learn how all the things have been compiled and put together from source.

    • I think it’s a great idea to do a new native Android port of Emacs for use within Terminal IDE — I don’t have the time to do it, but I certainly have the time to test, and will happily update this blog post with a link if/when you have one ready.

      In the meantime, http://emacs.zielm.com seems to be back up again. We should probably mirror it, in case the site goes offline permanently.

  9. Nice, brilliant and thanks! Finally got “emacs for Android” working, and it even recognizes org.mode.

  10. Andreas says:

    I installed everything according to the instructions and it works fine, but:

    Terminal IDE does not support UTF-8.

    Non-ASCII characters are not displayed.
    (It is mentioned in the Playstore description.)

    There is a feature request on the project page but the last comment was 1 year ago.
    It seems Terminal IDE development is resting.

  11. Mark says:

    Nice HowTo. Thx!
    Would you also have an idea how to apply your approach to a different terminal app?
    More specifically to Jack Palevich’s Terminal Emulator for Android?
    I followed your approach for that one, but invoking emacs I get an error message right from the start, saying that the ‘Terminal type’ would not be supported.
    I tried putting the terminfo files from http://emacs.zielm.com/data/ into various places on my device and also tried to set TERM and TERMINFO in various ways, but I admittedly I don’t really know what I am doing, and consequentially I cannot get it to work.
    Any help would be most appreciated.

  12. Sergey says:

    Lovely, thanks!
    For people with emacs crashing on startup – it crashes for me in portrait mode, but not in landscape. Suppose there’s a minimum screen width requirement…

  13. Luca says:

    Hi David, which bt keyboard do you use along with your tablet and emacs? Plus, do you know if it is possible to swap the Ctrl key and the Bloc Maiusc key? This is the way I have my keyboard set up on my computer, and it is one of the few things preventing the transition to tablet from happening!

    Thanks in advance, and thanks for your article!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s