Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run Visual Studio Code for Linux from WSL on Windows 10

Run Visual Studio Code for Linux from WSL

Thanks a lot to mredbishop and others for their insturctions posted here. This is just a recap of what they figured out.

This process was tested on WSL Ubuntu 18.04.

Install VcXsrv on Windows

  1. Dowload the VcXsrv installer from https://sourceforge.net/projects/vcxsrv/
  2. Install the software on Windows

Add VS Code repositories

On your linux terminal, execute the following commands to install some required dependences:

sudo apt-get install libgtk2.0-0
sudo apt-get install libxss1
sudo apt-get install libasound2

Then run the following commands to add the VS Code repos for apt:

cd ~
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

Install VS Code on Linux

Run the following to install VS Code on Linux:

sudo apt update
sudo apt install code
sudo apt install code-insiders

Bash config

Add the following at the end of your .bashrc (or .zshrc if using ZSH):

# X Server
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY=0:0
sudo /etc/init.d/dbus start &> /dev/null

Note: to edit your bashrc file you can run nano ~/.bashrc (or nano ~/.zshrc if using ZSH).

Now reload the file by executing source ~/.bashrc (or source ~/.zshrc if using ZSH).

Grant no-password access for dbus

We now need to add a sudoers file to grant our user password-less root access to the dbus service.

  1. Run the following command:
sudo visudo -f /etc/sudoers.d/dbus
  1. Then paste the following text inside the Nano editor that will launch (Replace your_username with your linux username):
your_username ALL = (root) NOPASSWD: /etc/init.d/dbus
  1. Press CTRL+O to save the file, then press Enter to confirm. Finally, press CTRL+X to close the Nano editor.
  2. Now close you Linux terminal and open a new one.

Launch VS Code

  1. On Windows launch the recently installed XLaunch app.
  2. In the dialog, always choose Next and then Finish. NOTE: uncheck the Primary selection checkbox in the 3rd step otherwise everything you select in VS Code will also be copied in the clipboard.
  3. Finally, on your linux terminal, navigate to your desired folder and run code . (or code-insiders .)
  4. VS Code for Linux should launch

VS Code is blurry on High DPI monitors

If you use a 4K monitor, chances are your VS Code appears blurry. There is a workaround for this but, at least on my machine, it makes VS Code laggy and a bit unresponsive. Anyways, here it is:

On windows:

  1. Open the C:\Program Files\VcXsrv folder.
  2. Right click on the vcxserver.exe file and choose Properties.
  3. From the Compatibility tab, click the Change hi DPI settings button.
  4. Turn on the Override high DPI scaling behaviour checkbox and choose Application in the dropdown menu just below.
  5. Press OK and save.
  6. Close VcXserver and re-launch it.

On Linux, add the following at the end of your .bashrc (or .zshrc if using ZSH):

export GDK_SCALE=2

Note: to edit your bashrc file you can run nano ~/.bashrc (or nano ~/.zshrc if using ZSH). Then reload the file by executing source ~/.bashrc (or source ~/.zshrc if using ZSH).

@Biswa96

This comment has been minimized.

Copy link

Biswa96 commented Sep 14, 2018

Insider build requires libgtk-3.0. One can download DEB package from:

In my 1366 x 768 display, VSCode runs well without configuring dbus and DPI settings.

@panteluke

This comment has been minimized.

Copy link

panteluke commented Oct 3, 2018

Everything works perfectly. I have a small problem. I cannot install any extension on Visual Studio Code. I get permission denied when extension tries to get written to my home folder!

@joddm

This comment has been minimized.

Copy link

joddm commented Nov 15, 2018

Which Windows build is minimum to get this to run? Currently running version 1709, build 16299.726, and wondering how far I need to update

Edit: Updated to version 1809, working fine now 💯

@seffyroff

This comment has been minimized.

Copy link

seffyroff commented Nov 15, 2018

code crashes vcxsrv for me when I try to run it. Sadly I've been hacking around in WSL a bit and probably broke something somewhere trying to make this work.
EDIT: I installed the trial of X410 and Code works. So I guess my hacking didn't break that, but something is upsetting Vcxsrv. I do have the same permissions issue as @panteluke above however.
EDIT2: Could be a vscode issue - I do seem to be able to install extensions in code-insiders..

@genesy

This comment has been minimized.

Copy link

genesy commented Dec 13, 2018

Code also crashes vcxsrv for me. Using x410 works.

@amir-shehzad

This comment has been minimized.

Copy link

amir-shehzad commented Dec 15, 2018

I want to use shift + home (on Numpad), as a home button instead of digit since i use it very frequently. But it is not happening. Can you see how it can be done?

@sweenish

This comment has been minimized.

Copy link

sweenish commented Dec 17, 2018

Debian WSL requires the extra packages apt-transport-https & curl to download and use Microsoft's repository.

@Adrian-LL

This comment has been minimized.

Copy link

Adrian-LL commented Dec 20, 2018

Maybe it is a little late, but I also had the same issue as @panteluke and @seffyroff with extension installation.
It worked though via manual vsix download and install. (just my 2 cents).
However code crashes randomly and sometimes has a very bad windows redrawing.
(tested under Mobaxterm, under vcxsrv it did not work at all).
Also sublime text worked like a charm and very quick...

@kuops

This comment has been minimized.

Copy link

kuops commented Dec 28, 2018

Error code: 3 (Window), ID: 0x00280034, Major opcode: 25 (SendEvent), Minor opcode: 0 ((null))

window can‘t maximize or minsize

@NikitaCartes

This comment has been minimized.

Copy link

NikitaCartes commented Jan 8, 2019

Not working under MobaXterm and under VcXsrv.
After code . happens nothing and --verbose is empty.
But after each launch VcXsrv has two more clients.
default

Windows 1809 and Debian in WSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.