Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xerootg/23387b8fb03278dde83e1a46f26f27e8 to your computer and use it in GitHub Desktop.
Save xerootg/23387b8fb03278dde83e1a46f26f27e8 to your computer and use it in GitHub Desktop.
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

Run all the things

On your linux terminal, put this in some file and run it:

sudo apt-get install libxss1 -y
sudo apt-get install libasound2 -y
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'
sudo apt-get update -y
sudo apt install code -y
sudo apt install code-insiders -y
echo \# X Server >> ~.bashrc
echo export LIBGL_ALWAYS_INDIRECT=1  >> ~.bashrc
echo export DISPLAY=127.0.0.1:0.0  >> ~.bashrc
echo sudo /etc/init.d/dbus start \&\> /dev/null  >> ~.bashrc

Now reload your profile 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment