Fully Integrate Linux into VS Code on Windows

Fully Integrate Linux into VS Code on Windows

Linux is a cancer that attaches itself in an intellectual property sense to everything it touches.

Steve Ballmer, Microsoft CEO, June 2001

This ain’t yer Dad’s Microsoft…

In the past few years, Microsoft has made Visual Studio Code, the free code editor that runs everywhere, into the preferred choice of many developers. And, rather than relentlessly pushing their own alternative, they’ve built the Linux command line into Windows as the Windows Subsystem for Linux.

If you’re like me, you’ve already set up both your WSL Linux shell and your VS Code environment just how you like ’em. But when you open the integrated terminal, you’re disappointed to see a Powershell prompt …

VS Code integrated Powershell terminal
VS Code’s default integrated terminal is Powershell

Let’s fix that …

tl;dr

  1. Set your integrated shell:
            "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe"
          
  2. Install the Remote Development Extension Pack
  3. Open your project from the Linux shell
  4. Install extensions in WSL

[ez-toc]

Use the right shell

By default, VS Code uses Powershell on Windows 10, but it’s easy to change. Just set the path to your WSL executable as the integrated shell for Windows in your settings:

  1. Click the gear icon near the lower left corner.
  2. Click Settings, then click the curly braces near the upper right corner.
    • This opens the settings.json file directly rather than using the GUI to change the setting. If you prefer the GUI, read more below.
  3. Add a property for terminal.integrated.shell.windows and set it to the full path to wsl.exe.
    • You have to double-up the backslashes in the path definition because JSON uses the backslash as an escape character.
    • Don’t forget to add a comma at the end of the previous entry, or at the end of this new entry if you’re not putting it at the end.
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe"
Add WSL as integrated terminal for Windows in settings.json
Changing the integrated shell in settings.json
If you prefer to change settings in the GUI:
  1. Click the gear icon near the lower left corner.
  2. Click Settings.
  3. Enter integrated shell windows into the Search Settings field.
  4. Enter the full path to wsl.exe as the value of the Terminal﹥Integrated﹥Shell: Windows
Change your integrated shell using the GUI
Changing the integrated shell using the GUI

Note that this has to go in the User settings. For “enhanced security“, you can’t set a different shell for each workspace (project).

Make VS Code work in Linux

We’ve configured VS Code to open the Linux shell in the integrated terminal, but it still runs itself in the Windows environment. This is a problem for extensions that work by processing the output of command line tools. You could install them in the Windows shell, but you you wouldn’t be here if you wanted to work in the Windows shell. Besides, most of these tools were written for a *NIX shell. Installation on Windows usually isn’t easy, well-documented, or frequently updated when compared to installation in a Linux shell.

ESLint failed error message in VSCode
The ESLint extension fails on Windows.

As of the May 2019 release (or sooner if you’re using VS Code Insiders), Microsoft has provided a solution for this problem in the Remote Development Extension Pack. Remote – WSL (included in the pack) allows VS Code, running from Windows, to work with your code in the Linux shell.

VSCode Remote Development Extension Pack
Install the Remote Development Extension Pack

The first time you run VS Code from the Linux shell after installing the extension pack, it’ll spend some time “Installing VS Code Server”.

Install Extensions in WSL

Now that everything’s ready to go, you have to tell VS Code which of your extensions you want to work in WSL. Extensions that are already installed locally will have an “Install on WSL” button. Extensions that aren’t installed yet will install on WSL by default when you’re working in a WSL project.

VS Code: Install on WSL
Install your extensions on WSL
, ,