Skip to content

Running VSCode for Linux in WSL #2760

Closed

Description

@mredbishop

I'm creating a new issue for this as the previous two got way off track talking about the windows version of VS Code from WSL.

I now have VS Code for Ubuntu installed in the Ubuntu WSL in windows at version 1.19.0-insider

To get to the point at which I am at, install an XServer for windows, I use VcXsrv with the following settings:
image
image
image

Then, in WSL you need at least the creators update, do the following:
Install the required libs

ed@ed-surface-book: sudo apt-get install libgtk2.0-0
ed@ed-surface-book: sudo apt-get install libxss1
ed@ed-surface-book: sudo apt-get install libasound2

Add VS Code repository

ed@ed-surface-book: curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
ed@ed-surface-book: sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
ed@ed-surface-book: 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 Insiders (and code itself if you like)

ed@ed-surface-book: sudo apt-get update
ed@ed-surface-book: sudo apt-get install code
ed@ed-surface-book: sudo apt-get install code-insiders

Set the environmental paramaters

ed@ed-surface-book: export LIBGL_ALWAYS_INDIRECT=1
ed@ed-surface-book: export DISPLAY=0:0

NOTE At this point you need the DBUS service to be running (thanks Kinman Lam (@kinmanlam), I forgot :) ):

sudo service dbus start

Attempt to run VS Code Insiders with verbose logging so you see any issues

ed@ed-surface-book: code-insiders --verbose
[6398:1218/130534.978077:WARNING:audio_manager.cc(295)] Multiple instances of AudioManager detected
[6398:1218/130534.978163:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected

I now have only two warnings about multiple instances of AudioManager being detected and no errors. When clicking exit in XServer, it reports that there are clients connected so VS Code seems to be attaching to the XServer instance however the app does not display in the XServer window.
image

As there are no further errors in the verbose output I am stuck as to where to go next to debug this, are there any other logs/output sources I can look into?

Related:
Running VS Code native in WSL
Support launching VS Code from Bash on Ubuntu on Windows

commanderturner

Activity

  1. jack-guy commented on Dec 18, 2017

    @jack-guy

    therealkenc Has done a lot of investigating on this. Two recent comments by him that shed some light on why this is happening:
    #2293 (comment)
    #2293 (comment)

    FWIW in my time experimenting with running my own electron app on WSL, I believe I encountered the same event loop problem. Ultimately, the addition of

    setInterval(() => {}, 1);

    to the main process kept the event loop spinning in the background. I have no clue why that worked, however. Maybe someone could try plugging that line into a custom VSCode build to see if it works?

  2. khuongduybui commented on Dec 19, 2017

    @khuongduybui

    Wait, so someone planned to close the issue in microsoft/vscode#13138 and link here because (s)he thought the issue had nothing to do with VSCode and instead a problem with WSL.

    I followed the link here only to find out what the next step is probably a PR to Microsoft/vscode ???

  3. jack-guy commented on Dec 19, 2017

    @jack-guy

    Duy K. Bui (@khuongduybui) The one-liner I recommended would be a hack that could help verify the underlying event loop issue in running VS Code (if it even works). This is 100% a problem with WSL, as is elaborated on in the comments I linked.

  4. khuongduybui commented on Dec 19, 2017

    @khuongduybui

    ok thanks for the clarification.

  5. mredbishop commented on Dec 19, 2017

    @mredbishop
    Author

    Duy K. Bui (@khuongduybui) Yeh sorry for not being clearer, based on what therealkenc and Harangue have found out, it looks like the event loop locks up on WSL where this doesn't happen in "clean" Linux.

  6. khuongduybui commented on Dec 20, 2017

    @khuongduybui

    Guys, I just updated to 17063. Code is running now, wow!

    2017-12-20

  7. mredbishop commented on Dec 20, 2017

    @mredbishop
    Author
  8. mredbishop commented on Dec 20, 2017

    @mredbishop
    Author

    Do I close this issue now or wait until it's in the mainstream release?

  9. WSLUser commented on Dec 20, 2017

    @WSLUser

    I think it's safe to say you can close it but therealkenc or somebody will need to add the "fixed in insiders build" tag. Question is if the fix for this can be backported to 16299.

  10. NellyWhads commented on Dec 24, 2017

    @NellyWhads

    Hey guys (espeically Duy K. Bui (@khuongduybui) ), been trying to set this up as well. Few questions:

    1. When running code through WSL, (natively installed in WSL), will I be able to safely edit linux files? I know you can launch the windows-installed vscode from WSL, but this will not allow for safe editing since windows doesn't handle all of the permission setting required by linux.
    2. Can someone test if this works with the regular version of VSCode (non-insiders)? If so, how'd you get it to work? I'm currently struggling with it (Windows Insiders build 17063)
  11. AndrewPardoe commented on Dec 25, 2017

    @AndrewPardoe

    Thanks for all the investigation! I've verified that this works with non-insiders Code, on Windows Insider build 17063.

    I'm running VCXsrv, multiwindow, no special configuration. I added the LIBGL line to my .bashrc, in addition to the DISPLAY line that's always been there. You also need to be running dbus: sudo service dbus start

    export DISPLAY=0:0
    LIBGL_ALWAYS_INDIRECT=1
    

    I installed Code (non-insiders) using the commands from above:

    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
    sudo apt-get install code
    

    Running Code is slow, but it works. A few times Code failed to launch completely and I had to kill it using Task Manager. As expected, it can create and edit files in your Linux paths.

  12. mredbishop commented on Jan 8, 2018

    @mredbishop
    Author

    Interestingly, this has stopped working for me again now 😢 with a Pulseaudio issue:

    ed@ed-surface-book:~$ code --verbose
    Assertion 'pthread_mutex_unlock(&m->mutex) == 0' failed at pulsecore/mutex-posix.c:108, function pa_mutex_unlock(). Aborting.
    

    Up to now (for the last 19 days) this was working almost flawlessly and was my main coding environment.

  13. therealkenc commented on Jan 8, 2018

    @therealkenc

    Assertion 'pthread_mutex_unlock(&m->mutex) == 0' failed at pulsecore/mutex-posix.c:108, function pa_mutex_unlock(). Aborting.

    That is #486 aka #1006, as explained in #648 (message) and Microsoft/vscode#13138 (message).

  14. 6 remaining items

  15. mredbishop commented on Feb 18, 2018

    @mredbishop
    Author
  16. manooog commented on Feb 23, 2018

    @manooog

    Duy K. Bui (@khuongduybui) hi,can you tell me which way that you get the 17063 insider build?thanks!

  17. jawjop commented on Feb 23, 2018

    @jawjop

    @Xixi20160512
    Win key + I
    Search for "insider"
    Click "Windows Insider Programme settings"
    Sign up to Insider builds. The settings you want to select are "Active development of Windows" and "Slow" ring.

    I just did this to test the solution. My PC is currently downloading version 17074.1002

    EDIT:
    And it works :) VS Code is running perfectly on WSL (aside from a bunch of dbus/pulseaudio errors). Thanks lads!

  18. therealkenc commented on May 25, 2018

    @therealkenc

    Ran course.

  19. jgoux commented on Aug 6, 2018

    @jgoux

    Hello,

    it seems that of today (Windows 10 build 17730.1000 + Code Insiders 1.26.0), the settings are a little different than the one you provided to make it works.

    I didn't need to make these 2 instructions :

    sudo apt-get install libgtk2.0-0
    export LIBGL_ALWAYS_INDIRECT=1

    And I needed to install the following :
    sudo apt-get install libgl1

    Also, to get rid of the error libGL error: failed to load driver: swrast, I needed to launch VcXserver with the -nowgl option : vcxsrv.exe :0 -ac -terminate -lesspointer -multiwindow -clipboard -nowgl

    I've put these at the end of my ~/.bashrc so they get started automatically :

    # WSL
    sudo /etc/init.d/dbus start &> /dev/null
    export DISPLAY=:0
    

    Hope this helps! 😄

    I still have a lot of these warnings :

    [952:0806/112602.063993:ERROR:bus.cc(395)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
    [952:0806/112602.066028:ERROR:bus.cc(395)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
    

    Does anyone have any idea if it's solvable?

  20. sworisbreathing commented on Aug 21, 2018

    @sworisbreathing

    I don't quite understand why this issue was closed. It's not working for me.

  21. fedme commented on Aug 28, 2018

    @fedme

    This is working for me, thanks!

    I've written a more detailed and beginners-proof version of the installation steps you provided here.

    Still, VS Code is blurry on High DPI monitors. Anyone knows how to fix that?
    Overriding Windows' DPI settings for VcXserver works but makes VS Code very unresponsive for me.

  22. spences10 commented on Sep 14, 2018

    @spences10

    This is working for me, thanks!

    I've written a more detailed and beginners-proof version of the installation steps you provided here.

    Still, VS Code is blurry on High DPI monitors. Anyone knows how to fix that?
    Overriding Windows' DPI settings for VcXserver works but makes VS Code very unresponsive for me.

    That Gist you linked is a 404 Federico Meini (@fedme) 😢

  23. fedme commented on Sep 14, 2018

    @fedme

    That Gist you linked is a 404 @fdmnio 😢

    Updated the link, sorry for that!

  24. photon-schiesser commented on Nov 3, 2018

    @photon-schiesser

    I cannot get this to work. I have followed the instructions, but nonetheless, code-insiders does not show any activity in the XWindow and nails my CPU.

    Here is the output. Seems to be multiple errors, but I am having trouble tracking down how to fix any of them. Help would be appreciated.

    me@mypc:~$ code-insiders --verbose
    shared memfd open() failed: Function not implemented
    [main 12:48:20 PM] Starting VS Code
    [main 12:48:20 PM] from: /usr/share/code-insiders/resources/app
    [main 12:48:20 PM] args: { _: [],
      help: false,
      h: false,
      version: false,
      v: false,
      wait: false,
      w: false,
      diff: false,
      d: false,
      add: false,
      a: false,
      goto: false,
      g: false,
      'new-window': false,
      n: false,
      'unity-launch': false,
      'reuse-window': false,
      r: false,
      'open-url': false,
      performance: false,
      p: false,
      'prof-startup': false,
      verbose: true,
      logExtensionHostCommunication: false,
      'disable-extensions': false,
      disableExtensions: false,
      'list-extensions': false,
      'show-versions': false,
      nolazy: false,
      issue: false,
      'skip-getting-started': false,
      'skip-release-notes': false,
      'sticky-quickopen': false,
      'disable-restore-windows': false,
      'disable-telemetry': false,
      'disable-updates': false,
      'disable-crash-reporter': false,
      'skip-add-to-recently-opened': false,
      status: false,
      s: false,
      'file-write': false,
      'file-chmod': false,
      'driver-verbose': false,
      trace: false }
    [main 12:48:20 PM] Resolving machine identifier...
    [main 12:48:20 PM] Resolved machine identifier: [myidentifier]
    [main 12:48:20 PM] update#setState idle
    [main 12:48:20 PM] windowsManager#open
    [main 12:48:21 PM] telemetry/optInStatus { optIn: true }
    [3783:1103/134829.985597:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3812:1103/134844.482518:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3817:1103/134857.953995:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3822:1103/134911.182410:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3827:1103/134914.499644:ERROR:gl_implementation.cc(245)] Failed to load /usr/share/code-insiders/swiftshader/libGLESv2.so: /usr/share/code-insiders/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
    [3827:1103/134914.501255:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3831:1103/134917.610325:ERROR:gl_implementation.cc(245)] Failed to load /usr/share/code-insiders/swiftshader/libGLESv2.so: /usr/share/code-insiders/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
    [3831:1103/134917.612414:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3835:1103/134920.852607:ERROR:gl_implementation.cc(245)] Failed to load /usr/share/code-insiders/swiftshader/libGLESv2.so: /usr/share/code-insiders/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
    [3835:1103/134920.854210:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3839:1103/134923.549052:ERROR:gl_implementation.cc(245)] Failed to load /usr/share/code-insiders/swiftshader/libGLESv2.so: /usr/share/code-insiders/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
    [3839:1103/134923.550639:INFO:child_thread_impl.cc(839)] ChildThreadImpl::EnsureConnected()
    [3751:1103/134923.642853:ERROR:browser_gpu_channel_host_factory.cc(103)] Failed to launch GPU process.
    
  25. photon-schiesser commented on Nov 3, 2018

    @photon-schiesser

    What does winver tell you?

    Windows 10 Pro
    Version 1803 (OS Build 17134.345)

  26. therealkenc commented on Nov 3, 2018

    @therealkenc

    [3827:1103/134914.499644:ERROR:gl_implementation.cc(245)] Failed to load /usr/share/code-insiders/swiftshader/libGLESv2.so: /usr/share/code-insiders/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory

    sudo apt install mesa-utils

    Also don't export LIBGL_ALWAYS_INDIRECT, and it is DISPLAY=localhost:0 not 0:0.

    The memfd open() thing is a red herring, unrelated to vscode proper, and basically dupe #1209.

    Version 1803 (OS Build 17134.345)

    You're better off on 17763 aka 1809 for unrelated reasons but it should fly alright on 17134. If you subsequently get the audio_manager.cc fail that's #1006 aka #486.

  27. photon-schiesser commented on Nov 4, 2018

    @photon-schiesser

    therealkenc after a restart, it is now working. Though, I still see the following error, even though code-insiders is displayed.

    [199:1104/131300.762260:ERROR:gl_implementation.cc(245)] Failed to load /usr/share/code-insiders/swiftshader/libGLESv2.so: /usr/share/code-insiders/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
    [199:1104/131300.766015:ERROR:gpu_child_thread.cc(252)] Exiting GPU process due to errors during initialization
    

    Another red herring perhaps?

  28. therealkenc commented on Nov 4, 2018

    @therealkenc

    Another red herring perhaps?

    Hard to say. Something thinks that missing .../swiftshader/libGLESv2.so is part of the VSCode package (strictly speaking, a distant dependency thereof) but it isn't there. I don't have that path on my 1.29.0-insider either, but I also don't get the ERROR:gl_implementation.cc line out of code-insiders --verbose. So we'll call that difference between my run and your run "odd" and/or "unexplained". I can't (won't?) speculate on the cause. It would take a deep dive to see how your run makes it to gl_implementation.cc(245), and, I can't do that myself because I don't get there. It's a dive that probably isn't worth the trouble unless/until it becomes some kind of hard fail. I am sure there is a "good explanation", but it won't be one that has anything to do with WSL (with usual caveat that anything is possible). Make sure you have 'native opengl` unchecked in VcXsrv, but I don't think that will matter. Happy to hear you got it running.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions