4

Hello I'm newbie using an Linux environment and VS code. I've used windows terminal to access on WSL2 and it worked well.

I'm trying to set up development environment but WSL isn't working in VS code. How can I fix the problem here? It keeps showing "VS Code Server for WSL closed unexpectedly." message.

[2020-12-03 07:24:35.010] Resolving wsl+docker-desktop, resolveAttempt: 1
[2020-12-03 07:24:35.106] Starting VS Code Server inside WSL (docker-desktop)
[2020-12-03 07:24:35.106] Extension version: 0.51.4, Windows build: 19041. Multi distro support: available. WSL path support: enabled
[2020-12-03 07:24:35.107] No shell environment set or found for current distro.
[2020-12-03 07:24:35.317] Probing if server is already installed: C:\WINDOWS\System32\wsl.exe -d docker-desktop -e sh -c "[ -d ~/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f ] && printf found || ([ -f /etc/alpine-release ] && printf alpine-; uname -m)"
[2020-12-03 07:24:37.900] Probing result: found
[2020-12-03 07:24:37.901] Server install found in WSL
[2020-12-03 07:24:37.901] Launching C:\WINDOWS\System32\wsl.exe -d docker-desktop sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" e5a624b788d92b8d34d1392e4c4d9789406efe8f stable .vscode-server 0  '}
[2020-12-03 07:24:38.017] Setting up server environment: Looking for /root/.vscode-server/server-env-setup. Not found.
[2020-12-03 07:24:38.017] WSL version: 4.19.128-microsoft-standard docker-desktop
[2020-12-03 07:24:38.017] WSL2-shell-PID: 11
[2020-12-03 07:24:38.017] Starting server: /root/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/server.sh  --port=0 --use-host-proxy --enable-remote-auto-shutdown 
[2020-12-03 07:24:38.018] /root/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/server.sh: line 12: /root/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/node: not found
[2020-12-03 07:24:38.018] VS Code Server for WSL closed unexpectedly.
[2020-12-03 07:24:38.018] For help with startup problems, go to
[2020-12-03 07:24:38.018] https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips
[2020-12-03 07:24:38.021] C:\WINDOWS\System32\wsl.exe -d docker-desktop -e kill 11
[2020-12-03 07:24:38.171] WSL Daemon exited with code 0
2
  • what is the value specified in the terminal.integrated.shell.windows setting in VS Code? What does a command wsl -l -v executed in powershell/cmd give?
    – Victor S.
    Dec 4, 2020 at 20:20
  • These are shown in wsl -l -v commend ``` NAME STATE VERSION * docker-desktop Stopped 2 Ubuntu Stopped 2 Ubuntu-20.04 Running 2 docker-desktop-data Stopped 2 ```
    – leeway00
    Dec 12, 2020 at 5:07

11 Answers 11

13

I encountered the same problem, but it was solved by restarting the WSL2 distribution. I'm using Ubuntu-20.04, so I rebooted with the following command. After reboot, reopen VS Code and hopefully your problem will be solved.

wsl -t Ubuntu-20.04
2
  • 1
    +1 ... Note to others, the above command is executed in a cmd.exe prompt. Worked for me with just wsl -t Ubuntu which I identified via wsl -l... Thanks!
    – pooley1994
    Jun 7, 2022 at 13:31
  • wsl --shutdown is more intuitive/easier to remember, as noted in my comment below. Mar 30 at 16:33
6

In vscode setting, Remote WSL setting >> Extension setting Remote.WSL2:Connection Method select wsl2VMAddress

enter image description here

WSL2 version 2 uses a virtual private network which is different from Windows 10 host IP. it changes its IP address every time so... if VS code running inside WSL2 can pick up the change then it might work better. otherwise, we have to disable the autogeneration of IP in WSL2 side.

1
  1. In Vs Code ctrl+schift+p
  2. Open Preferences: Open Settings (JSON)
  3. Add "terminal.integrated.shell.windows": "wsl.exe",
  4. Reopen terminal.

If you need to open a specific distribution, then additionally for example:

  1. "terminal.integrated.shellArgs.windows": ["-d", "Ubuntu-20.04"],
  2. Reopen terminal.
2
  • It says "terminal.integrated.shell.windows" is deprecated for the VS Code version 1.59.0 Aug 13, 2021 at 8:39
  • Try to set the value "terminal.integrated.defaultProfile.windows": null, for the latest versions of VS Code (the default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set) and also remove terminal.integrated.shell.windows and terminal.integrated.shellArgs.windows.
    – Victor S.
    Aug 17, 2021 at 6:24
0

In vscode terminal:

which node

and pasted the path to launch.json:

"runtimeExecutable": "<path>/node/v14.15.5/bin/node",
0

The issue was solved in my case by opening the Ubuntu terminal and starting vscode from there. There was a missing package in wsl that I couldn't install by editing any config file from vscode. After installing that package, vscode was able to start the remote connection with wsl

0

Windows update disabled Virtualization in my BIOS. You can run the wsl command in PowerShell to check if the wsl environment is ok.

0

I encountered the symptoms of this problem after upgrading from Windows 10 to Windows 11. My actual underlying problem was that WSL was unable to mount the .vscode extensions folder in /mnt/c/users/username/. This was caused by having a custom kernel defined in .wsconfig. In order to find this problem it was also important to increase verbosity and check dmesg in the WSL environment.

See this issue for details: WSL2 Windows Drive Not Mount 4226

0

This happened to me after visual studio update. I opened it via terminal and it worked.

0

This is the new way to add WSL to your VS Code settings.json:

  1. In VS Code ctrl+shift+p
  2. Open Preferences: Open Settings (JSON)
  3. Add:

{
"Ubuntu (WSL)": {
      "path": "C:\\WINDOWS\\System32\\wsl.exe",
      "args": ["-d", "Ubuntu"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "Ubuntu (WSL)",
}

  1. Reopen terminal.
1
  • I believe you have an extra brace in there, but that's great
    – Jon
    Jul 18 at 14:25
0

You can reboot WSL from PowerShell by typing wsl --shutdown, and then just open/use WSL in any way to restart it.

0

On Windows, from VSCode(RunElevated), could not connect to WSL. stuck after download VS Code Server.

But from Ubuntu CLI, "code ." could able to download VS Code Server. All good.

enter image description here

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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