How to use Sublime Text 3 from command line with Ubuntu Bash Terminal in Windows 10 Subsystems for Linux (WSL)

Patrick Kilgore
3 min readNov 22, 2016

--

It works!

12/17/16 Update: I no longer use this setup. Instead, I use the setup explained in this awesome tutorial by Nick Janetakis here, and for many of the same reasons. I highly encourage you to check it out — particularly because of the copy+paste support between WSL applications and windows applications.

I’m assuming that you’ve already got bash up and running on Windows 10. If not, do that first by following instructions here.

11/14/2017 Update: With the roll out of the “Fall Creator’s Update” to Windows 10, WSL has left beta. While this is generally good news for Sublime compatibility, the announcement also explicitly states that Microsoft has “NO current plans to support X/GUI apps, desktops, servers, etc. at this time”. So be warned that what I explain how to do below is not a supported use-case for WSL — even though it still appears to work just fine. Drop me a note, however, if you’re having any issues with these instructions after the update.

Installing a Windows X Server (Xming)

First things first, in order to display anything running in WSL in a graphical interface, we need to install an X server for Windows. The general idea here is that WSL will output to X, and your X server will convert that output to something that appears in a window on Windows 10.

There are a variety of X servers for windows out there. We will use xMing. Download it, install it, and run it. You’ll know it’s up and running by the small icon that appears in the windows system tray. Remember: You will need to make sure xMing is running in Windows 10 each time before you start Sublime.

Now, we will configure bash to send X window output to Xming by default. The command below appends the line export DISPLAY=localhost:0.0 to your user .bashrc file so you don’t have to type in something similar each time you open bash.

echo 'export DISPLAY=localhost:0.0' >> ~/.bashrc

Make sure close and restart bash after running this command. You should only ever have to run this command once, unless you delete or otherwise remove the line from your .bashrc file.

A more detailed explanation of what a .bashrc file does is outside the scope of this tutorial. You can also edit your .bashrc file with nano (nano ~/.bashrc), but you’ll have to learn how to use nano from another tutorial.

Installing necessary gtk components

Sublime needs some graphical components from the GTK libraries that apt isn’t smart enough to download automatically. We can install them with this command:

sudo apt-get install libgtk2.0-0

Make sure to accept any dependencies apt asks you to install.

Installing Sublime from the webupd8team repository

While I have no doubts you can also follow this tutorial after you compile from source yourself, for the purpose of this tutorial we are going to use the sublime deb package prepared by the folks at webupd8team.

  1. First we add the repository for the package.
sudo add-apt-repository ppa:webupd8team/sublime-text-3 -y\

2. Then we update apt’s database to include the new packages from the repository.

sudo apt-get update

3. Then we install sublime:

sudo apt-get install sublime-text-installer

Make sure to accept any dependencies apt asks you to install.

Finally, we create a link to the sublime executable so that you can run the subl command from bash — the installer should do this, but it did not for me:

ln -s /opt/sublime_text/sublime_text /usr/local/bin/sublime_text

At this point, sublime should work as you can see in the screenshot above. I haven’t explored how far I can push it yet, but I don’t expect it to be 100% compatible as WSL has not completely implemented every feature of linux.

Comments welcome!

What works

  • Sublime Package Manager
  • Themes (Flatland Dark works, at least)

What doesn’t work

  • Windows clipboard will not be accessible in Sublime

--

--