26

I am trying to run a Python project on the WSL (Ubuntu-18.04 distribution) system with VS code. I have the WSL - Remote plugin v0.39.9 installed. When run the command:

code .

Receive the error:

/home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390/bin/code: 12: /home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390/bin/code: /home/username/.vscode-server/bin/6ab598523be7a800d7f3eb4d92d7ab9a66069390/node: Exec format error

When I ran inside the VS Code trying to connect to the WSL instance:

Starting VS Code Server inside WSL (Ubuntu-18.04) Extension version: 0.39.9, Windows build: 18362. Multi distro support: enabled. WSL path support: enabled VS Code Server for WSL closed unexpectedly.

This is the information of VS Code:

Version: 1.39.2 (user setup)
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:35:18.241Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362
6
  • Are you using stable version of VSCode? Did you try with VSCode insider builds? Can you check the node file is a ELF 64 binary with file command? Also is it has a executable flag chmod +x?
    – Biswapriyo
    Nov 6, 2019 at 14:47
  • @Biswapriyo, please see the update with the VS code version information. Forgive me I´m newbie, how can I find the node file that you refer? Nov 6, 2019 at 16:04
  • Yes, this file has the executable permissions for Owner, Group and Everyone, -rwxr-xr-x. I see two folders inside the bin folder: 6ab598523be7a800d7f3eb4d92d7ab9a66069390 and f06011ac164ae4dc8e753a3fe7f9549844d15e35 Nov 6, 2019 at 16:31
  • 6
    There is risk to take, delete the folder /home/username/.vscode-server/. VSCode remote extension will automatically install it in WSL.
    – Biswapriyo
    Nov 6, 2019 at 16:59
  • @Biswapriyo This did not work :-( Feb 20, 2020 at 16:16

7 Answers 7

67

I solved this problem by shutting down wsl and then restarting it in powershell.

wsl --shutdown
wsl
5
  • 1
    I just restarted my system :)
    – Jawaid
    Jun 7, 2021 at 11:30
  • 1
    the restart would accomplish the same thing
    – TygerTy
    Jul 7, 2021 at 7:10
  • This helped thanks
    – Jijo
    Jan 10, 2022 at 6:37
  • 1
    anyone know why this happens?, when it occurred to me I switched wireless networks on my laptop, but no idea if this is related. Feb 19, 2022 at 13:27
  • 3
    I really wish WSL reached the maturity level where 'have you tried turning it off then on again?' weren't the correct solution for 60% of the problems.
    – szmate1618
    Sep 23, 2022 at 16:28
14

Can the problem be that you have an outdated VS Code Server on your WSL and have docker (instead of a Linux version) selected as your default WSL distro?

Solution:

1. Open PowerShell and run wsl -l -v And check that an asterisk * indicates that Ubuntu (or other Linux distro) is your default WSL distro.

* Ubuntu-20.04           Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

If not, run in PowerShell wslconfig /setdefault <Your WSL Linux distro>

2. When you have the correct WSL distro selected, open VSCode, press Ctrl+Shift+P, and type Remote-WSL: New WSL Window. This will update VS Code Server on your WSL Linux distro.

3. code . should now work in WSL

I had a similar problem that occurred after updating VSCode. I recognized it when I tried to open VSCode from Ubuntu and received the following error:

~$ code .
Updating VS Code Server to version 507ce72a4466fbb27b715c3722558bb15afa9f48
Removing previous installation...
Installing VS Code Server for x64 (507ce72a4466fbb27b715c3722558bb15afa9f48)
Downloading: 100%
Failed
--2021-06-29 10:48:51--  https://update.code.visualstudio.com/commit:507ce72a4466fbb27b715c3722558bb15afa9f48/server-linux-x64/stable
Resolving update.code.visualstudio.com (update.code.visualstudio.com)... failed: Temporary failure in name resolution.
wget: unable to resolve host address ‘update.code.visualstudio.com’
ERROR: Failed to download https://update.code.visualstudio.com/commit:507ce72a4466fbb27b715c3722558bb15afa9f48/server-linux-x64/stable to /home/username/.vscode- server/bin/507ce72a4466fbb27b715c3722558bb15afa9f48-1624952921.tar.gz
3
  • This solution works well and doesn't require shutting down wsl. Mar 23, 2022 at 0:55
  • This did it for me. Thank you! I had docker desktop and it was being used as the default distro.
    – Joan Gil
    Mar 27, 2022 at 23:07
  • This worked for me as well. I've should realize it tho 'cause the logs were specifically saying that docker-desktop-data wasn't working... Many Thanks! Oct 24, 2022 at 13:29
14

This is what worked for me:

  • Inside a wsl prompt, I deleted the .vscode-server folder inside home directory using rm -rf ~/.vscode-server
  • Spawned a vscode from WSL using code ~ , which caused a reinstall of VS Code Remote

Credits go to Gustavo Gondin: https://ggondim.medium.com/vs-code-server-for-wsl-closed-unexpectedly-8672b28cc11f

1
  • 3
    This worked for me, but as a heads-up for others: be aware that this also removes any remote extensions you may have installed in your WSL envirnonment. VS Code fortunately will indicate on next boot that it is missing some remote extensions, but better to be safe than sorry and prepare for this.
    – Kazu
    Aug 15, 2022 at 12:19
4

I had the same problem, and turns out that I had as default docker-desktop-data. That distro doesn't have a shell environment so you can set the default distro to be docker-desktop instead and avoid installing anything:

C:\> wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop-data    Running         2
  docker-desktop         Running         2
C:\> wsl -s docker-desktop
C:\> wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop         Running         2
  docker-desktop-data    Running         2

Then, the command executed by the WSL vscode extension will ask for node installed in that wsl and it will fail.

You then realize here that something extra needs to be done and it won't work out-of-the-box. You may select or install your desired wsl using:

  • Choose "using distro" List item
  • If you don't have any, install a new one: select

and that will take you to the microsoft store. I would recommend installing the Alpine distro that's the lighweight you may find.

2

This works for me too

wsl --shutdown

Then, I reopened my VS and opened my remote folders. This might happen because you abruptly shut down your computer. In my case, I closed my laptop lid while I could still hear the fan.

0

Installing Ubuntu via Microsoft Store may result in version 1. In this case trying to open a remote window may cause to end up with

VS Code Server for WSL closed unexpectedly.
Check WSL terminal for more details

Restart does not help you here. Then check the WSL version.

wsl -l -v                  # Take a note your distribution name below
  NAME    STATE   VERSION
* Ubuntu  Running 1    

And if it is 1 try to change it to 2.

wsl --set-default-version 2
wsl --set-version Ubuntu 2 # will set your Ubuntu distribution to use WSL 2

It take some time to convert the version. When the process complete remote window opens successully.

0

If you restarted wsl,

restarted you pc

turned the windows feature on

enabled virtualization in bios mode

and it still does not work

go to an elevated command prompt(command prompt as administrator)

type "bcdedit" and hit enter

if the hypervisorlaunchtype is set as Off,

type "bcdedit /set hypervisorlaunchtype Auto" and hit enter

basically turning it on from the "Turn windows feature on/off" is sometimes not enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.