Skip to content

Instantly share code, notes, and snippets.

@fedme
Last active November 8, 2023 09:33
  • Star 54 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fedme/604c6b811939468fdad06e3fbba942ed 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

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).

@genesy
Copy link

genesy commented Dec 13, 2018

Code also crashes vcxsrv for me. Using x410 works.

@data-scientist-ml1
Copy link

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
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
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
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
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.

@thisisbinod
Copy link

thisisbinod commented Feb 19, 2020

To me VS Code with Remote WSL makes more sense. Remote SSH is even better especially now they have added support for remote SSH for macOS.

@fedme
Copy link
Author

fedme commented Feb 20, 2020

@thisisbinod Sure, I agree. This is an old gist.

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