Emacs and the Windows Subsystem for Linux

About Emacs 25 in WSL

With Windows 10, Microsoft offers the ‘Windows Subsystem for Linux (WSL)’ that runs Linux binaries, including the Bash Shell, and Emacs, natively on Windows.

You can install Linux distros from the Windows Store. Currently Ubuntu, openSUSE and SUSE Linux are available, with several other distros on the way. You can also install and run multiple distros side-by-side on the same machine, and you can use each distro’s package manager to install all your favorite tools and apps.

WSL is improving rapidly in terms of completeness and compatibility, though you may encounter the occasional issue, in which case, please search and (if not found) file an issue on the WSL team’s GitHub Issues Repo: https://github.com/microsoft/wsl.

Here is how I install Emacs 25.

Install & Activate WSL

The official WSL Installation Guide: https://msdn.microsoft.com/commandline/wsl/install_guide

Check OS Type and Build of you System, there are minimal requirements. There is a choice between Linux distros.

Be sure to specify a non-su username and password when prompted - Linux usernames and password are separate from your Windows username and password.

Install a graphical Linux environment

Although only Linux commandline tools are officially supported on WSL many X applications work fine. In addition, you may want to install a Linux GUI/desktop, though this will require having all X applications in a dedicated toplevel window — follow the instructions on this page: https://solarianprogrammer.com/2017/04/16/windows-susbsystem-for-linux-xfce-4/

There are several X Servers for Windows, some of which include:

[The following is probably outdated with recent updates to WSL]

Most likely, you will get (DBus) errors (like I did) when trying XFCE4 with VcXsrv, i.e. by doing XLaunch (starting the X Server from the Windows Icon) and then calling ‘xfce4-session’ on the BASH command line. If so, follow points 2 and 3 of the instructions on this page:


DISCLAIMER: doing point 3 (fixing dbus) is entirely at you own risk! It worked for me, but in the comment section of the linked page, one commenter reports that WLAN stopped working and he had to reinstall Windows 10 after this.

At the time of this writing, you need all this to make the Emacs package manager work. Running the installed Emacs 25 as -nw works just fine without X environment, but then you have to figure out yourself how to get your favorite packages.

Install Emacs 25

Follow the instructions on this page (a big THANKS to SolarianProgrammer for his excellents Blog Posts):


With the preparations above, I have

Funny enough, the graphical Emacs only accepted keyboard input ‘M-x’ after I once opened the Menu with F10 or so …

Furthermore, one has to answer a prompt where to put the ELPA directory. I’m not yet settled on this decision, since this is a critical point (accidentally editing Linux files with Windows Tools might corrupt the whole system, its recommended to make those files (maybe edited by both systems) Windows files under /mnt or so (see last paragraph of the installation guide: https://msdn.microsoft.com/de-de/commandline/wsl/install_guide)

Fix /dev/tty problem

If “sudo emacs -nw” works, but “emacs -nw” results in:

“emacs: Could not open file: /dev/tty”

this workaround (as discovered here too https://alexschroeder.ch/wiki/2015-09-18_Emacs_and_TTY) should help:

“sudo chmod go+rw /dev/tty”

DISCLAIMER: It’s left to your own judgement if this opens any security issues or not (I don’t know).


Without GUI integration using X or xrdp, these functions provide basic copy/paste between emacs and Windows clipboard.

(defun wsl-copy-region-to-clipboard (start end)
  "Copy region to Windows clipboard."
  (interactive "r")
  (call-process-region start end "clip.exe" nil 0))

(defun wsl-clipboard-to-string ()
  "Return Windows clipboard as string."
  (let ((coding-system-for-read 'dos))
    (substring				; remove added trailing \n
      "powershell.exe -Command Get-Clipboard") 0 -1)))

(defun wsl-paste-from-clipboard (arg)
  "Insert Windows clipboard at point. With prefix ARG, also add to kill-ring"
  (interactive "P")
  (let ((clip (wsl-clipboard-to-string)))
    (insert clip)
    (if arg (kill-new clip))))

Windows Terminal

This section covers Windows Terminal (WT) running wsl.exe running emacs -nw.

Key bindings

Many default WT bindings use the control key, which causes some problems for emacs.

Disable C-c and C-v

C-c and C-v invokes Windows copy and paste. To disable this and pass them to emacs instead:

  1. Edit the settings.
  2. Comment out these bindings:
    //{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
    //{ "command": "paste", "keys": "ctrl+v" },
  1. Save the changes.