I’ve had the Linux Subsystem for Windows enabled for quite a while during the time it was in Beta. With the release of the Fall Creators Update, I ended up redoing my setup from scratch. As usual I grabbed Emacs and a bunch of other packages and was initially disappointed that I was looking at a text-mode only Emacs. That might have something to do with the lack of an X Server…

For a free X Server on Windows, I had a choice of Xming and VcXsrv. I had used Xming a long time ago and while I’m happy to pay for software, I figured I’d just go with something free for this initial proof of concept. Plus, I was curious about VcXsrv, so I picked that. I really like that its installer includes everything I needed right out of the box, including the fonts.

So, after a brief install and an ‘export DISPLAY=localhost:0’ on the Ubuntu command line, we have an Ubuntu Emacs running on in a window on my Windows desktop without using a third-party VM:

Screenshot of my desktop showing Emacs 24.5 running on Linux Subsystem for Windows
My desktop, running an X-Windows GNU Emacs 24.5 running on Linux Subsystem for Windows

So far, so good, but given that the Ubuntu subsystem on Windows is running Ubuntu 16.04 LTS, what we have is an older version of Emacs, specifically Emacs 24.5:

Screenshot of an Ubuntu GNU Emacs 24.5 running on Windows

Clearly, that won’t do. I was also rather curious if the Ubuntu subsystem was good enough so my previous instructions on building GNU Emacs on Ubuntu 16.04 would work. Let’s go find out!

First, it’s time to install the build dependencies for Emacs 24:

timo@odie-win8:~/hg-repos/lonecpp-wp$ sudo apt-get build-dep emacs24
[sudo] password for timo:
Reading package lists... Done
E: You must put some 'source' URIs in your sources.list

Ah well, not entirely unexpected – the source repository isn’t enabled. That’s easy, but I normally enable it from the GUI so I first had to figure out how to enable it from the command line. Which again turns out to be easy, all I have to do is edit /etc/apt/sources.list and uncomment the deb-src lines. Job done. I just uncommented the deb-src entries for the main, restricted, universe and multiverse repositories. That might have been more than I needed but should work fine. Also, don’t forget to run `sudo apt update` after enabling the repos!

Now I can install the build dependencies again:

sudo apt build-dep emacs24

… and after a long download of the usual plethora of packages, I have everything in place to build Emacs from source. Sticking to my usual approach of just using a current release version, I tried building Emacs 25.3 first.

Doing the usual configure/make/make install dance didn’t get me very far, unfortunately:

Dumping under the name emacs
**************************************************
Warning: Your system has a gap between BSS and the
heap (20719407 bytes).  This usually means that exec-shield
or something similar is in effect.  The dump may
fail because of this.  See the section about
exec-shield in etc/PROBLEMS for more information.
**************************************************
Makefile:736: recipe for target 'bootstrap-emacs' failed
make[1]: *** [bootstrap-emacs] Segmentation fault (core dumped)
make[1]: Leaving directory '/home/timo/build/emacs-25.3/src'
Makefile:398: recipe for target 'src' failed
make: *** [src] Error 2

Oops.

I haven’t had much time to research this issue yet, but it looks like I might have hit a quirk of the Linux Subsystem on Windows that isn’t necessarily present in Ubuntu 16.04 LTS.

As a quick test, I tried to build a different version. I picked Emacs pretest 26.0.90 as a suitable version – hey, nothing like a bit of living on the edge. To keep everything inside the Ubuntu Linux subsystem, I pulled it down using wget and ran through the usual sequence of configure/make/make install:

wget ftp://alpha.gnu.org/gnu/emacs/pretest/emacs-26.0.90.tar.xz
cd build-dir
tar xvJf emacs-26.0.90.tar.xz
cd emacs-26.0.90
./configure --prefix=$HOME/local
make && make install

The surprisingly good news were that pretest built fine – no core dumps when dumping emacs- and a quick check confirmed that it was running fine in a terminal window. Yay.

Screenshot showing a text mode Emacs pretest 26.0.90
Text mode only, but I have a running GNU Emacs pretest 26.0.90 on Linux Subsystem for Windows!

Time to push boundaries again, especially as the Fall Creators Update Linux Subsystem for Windows does not support X/GUI applications as per Microsoft. Unfortunately with this build, attempting to run the resulting binary as a GUI executable produced a bunch of errors and an empty window that only contained the menu bar.

~/local/bin/emacs

(emacs:15590): GLib-GObject-WARNING **: invalid unclassed pointer in cast to 'GtkWidget'

(emacs:15590): Gtk-CRITICAL **: gtk_widget_hide: assertion 'GTK_IS_WIDGET (widget)' failed

(emacs:15590): GLib-GObject-WARNING **: invalid unclassed pointer in cast to 'GObject'

(emacs:15590): GLib-GObject-CRITICAL **: g_object_get_data: assertion 'G_IS_OBJECT (object)' failed

I guess that might have been an attempt to push things a little too far. After all, Microsoft says that X/GUI apps aren’t supposed to work, so the simple fact that I was able to get the stock Emacs 24.5 working was a big surprise

I may try to figure out what’s causing these errors and see if I can get Emacs pretest working with X windows as well, if I can find the spare time…

9 thoughts on “Emacs on the Linux Subsystem for Windows”

  1. Hello, about “I just uncommented the deb-src entries for the main, restricted, universe and multiverse repositories. “.. I do not see any commented lines.. can you mention the exact lines that need to be in that sources.list file? Thanks.

  2. Looks like I might have to try this again at a later point.

    Building emacs-26 pretest fails with the same exec-shield error you got for building emacs 25.3. Also cannot modify randomize_va_space to have value 0 instead of 2 (even with sudo access.. probably because of corporate Win 10 installation?).

    Finally I tried “sudo apt-get install emacs24-nox”, and even that failed with:

    0% [Working]http: ../sysdeps/posix/getaddrinfo.c:2591: getaddrinfo: Assertion `(__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (sin6->sin6_addr.__in6_u.__u6_addr32); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == __bswap_32 (0xffff); }))’ failed.
    E: Method http has died unexpectedly!
    E: Sub-process http received signal 6.

    Probably a bad day ..

    1. Hi Kaushal,

      I’m sorry that you’re running into this issues – I’ll see if I can try to duplicate them on my system.

      I was just wondering if you are using the new Linux Subsystem for Windows that is available in the Fall Creators Update (the one where you have to install the Linux distribution from the Windows Store) or the older one that (at least on my system) is accessed via “Bash on Ubuntu on Windows”?

      All the tests I described above were done in the new Linux Subsystem, so that might explain some of the differences.

      That said, I just tested your ‘sudo apt-get install emacs24-nox’ in my “Bash on Ubuntu on Windows” that is also running Ubuntu 16.04.3 LTS as verified via lsb_release -a. I was able to install and run the packaged Emacs 24 after installing it via apt-get.

      Could you check if you’re running the same version of Linux?

      Thanks,
      Timo

      1. Thanks. Apparently that WSL version was the problem because I am on Windows 10 Enterprise whose release number is something like 141xx. So it’s definitely not the Fall Creators Edition.

        I later finally got the Emacs 26 pretest build working even on that version, running with my Emacs config 😀

        Though, I was not happy with the default color scheme and resolution of the Windows Console (I know that at some newer version after mine, Console gets 24-bit True color support, but I couldn’t upgrade as my Windows version is Enterprise version). Also the C-SPC binding wouldn’t work.

        So I then ended up with installing ConEmu — Awesome colors, with all bindings working as I like, and Iosevka font.

        Your post inspired me to try this out. Thanks 🙂

Leave a Reply