Solarian Programmer

My programming ramblings

Emacs 25 on Windows Subsystem for Linux

Posted on May 18, 2017 by Sol

Recently, a reader of this blog asked me about using Emacs under Windows Subsystem for Linux. According to the WSL documentation, Emacs, Vim and other Linux applications that run from console should work just fine. Turns out that the situation is a bit more complex. At the time of this writing, Emacs works fine for normal text editing. But, when you try to install a new package directly from Emacs, the program is stopped and sent to background and doesn’t seem to be able to cleanly recover when you use fg. From a practical point of view, this makes Emacs, under WSL, useless if you need to install any package that is not built in.

Fortunately, there is a workaround for the above bug and I will show you in this post how to avoid the problem. As far as I know, Emacs under WSL seems to work without a problem only if you install a desktop environment like Xfce 4. The idea is to use the GUI version of Emacs when you need to install a package. For normal editing, you can use Emacs from the WSL console.

I assume that you have a working WSL and a desktop environment, like Xfce, on your Windows 10 machine. If not, you can check my previous articles Install WSL - Windows Subsystem for Linux and Using the Windows Subsystem for Linux with Xfce 4.

Let’s make sure that you have an up to date system. Start WSL (use the Bash on Ubuntu on Windows console or write bash in a Command Prompt window) and write:

1 sudo apt update
2 sudo apt upgrade

At the time of this writing, WSL uses Ubuntu 16.04 which has Emacs 24 in his repositories. We can install Emacs 25.2, which is the current stable release, with:

1 sudo add-apt-repository ppa:kelleyk/emacs
2 sudo apt update
3 sudo apt install emacs25

If you are satisfied with the default Emacs configuration, this is all you need to do. Emacs will work just fine for normal text editing from the WSL console:

1 emacs -nw

this is what I see on my machine:

Emacs 25.2 in the WSL console

I assume that you want to install at least a few packages in Emacs to make your life easier. If you try to list, M-x list-packages, or install packages directly from the WSL console, you will hit the bug I’ve mentioned at the beginning of this article.

Use XLaunch to start an X server (see my previous article). You can find Emacs in ApplicationsDevelopment:

Emacs 25.2 in Xfce 4 under WSL

At this point, you can edit .emacs.d to fit your needs and install any package you need. Once you’ve finished, you can close the X server and use Emacs from a normal WSL console.

If you want to learn more about the Linux command-line applications, I would recommend reading The Linux Command Line by William E.Shotts Jr.

A good Emacs book is Mastering Emacs by Mickey Petersen.

comments powered by Disqus