Visual Studio Code not running/working on WSL 2
Asked Answered
C

4

6

Somehow when I run code . inside the WSL, it simply doesn't do anything. If I which code it does return the VS Code path on windows, but still nothing happens.

Camarillo answered 28/9, 2020 at 20:6 Comment(0)
C
31

After some research, what really fixed the issue for me was this:

  1. Within the WSL terminal, run rm -r ~/.vscode-server to delete the VS Code WSL server.
  2. Exit the terminal and from your PowerShell/Cmd, run wsl --shutdown.

Then you can go back to WSL and run code . and it should work normally.

Camarillo answered 28/9, 2020 at 20:6 Comment(6)
Thank you. I'm not sure why this happened but this helped me get my vscode running properly again.Allegedly
This did not work for me for some reason :( I wish it did.Trochee
also remove /.vscode-server-server i think they may have renamed the folderWhither
Thanks, I'm setting up on my wife's laptop code would not load from WSL. This worked great. Thank you.Treed
It happend for me after upgrading to wsl 2. I still cannot run VS code.Tephra
This works for me. But it wipes out the extensions installed. One has to re-install the ones really needed again.Talavera
T
3

I solved it following this post with slight modifications.

  1. exit all instaces of wsl
  2. From the power shell run wsl --shutdown
  3. Start VS Code on Windows
  4. Open a previously saved project which uses wsl (this is the difference)
  5. Open wsl and run code . starts VS Code for me

Note: the issue appeared for me after upgrading to wsl2

Tephra answered 16/11, 2022 at 15:44 Comment(1)
For me, wsl --shutdown causes Windows 10 to halt, but terminating the distros manually and closing wsl hosts from task manager works.Takeover
K
0

Another cause of this issue is if VS Code's bin directory isn't in your Windows Path.

You can check if VS Code is in your path correctly by attempting to launch it by typing "code" from a Command Prompt or Power Shell. If you can't launch from these then your Windows path to VS Code is missing or incorrect.

To fix this, first locate your install path for VS Code.

  1. Open your start menu and type "Visual Studio Code", then right click on "Visual Studio Code" and select "Open File Location", that should open an Windows Explorer window.
  2. If the file displayed in Windows Explorer is also a shortcut, then again right click and select "Open File Location".
  3. Repeat if necessary until you find yourself in a folder probably named "Microsoft VS Code" with a sub-folder named "bin".
  4. Right click the "bin" folder and select "Copy as path" or determine the path of the folder with "ALT + D" to select the path in the url bar in Windows explorer and copy it to the clipboard.
  5. In your start menu find "view advanced system settings" and launch it. Click "Environment Variables"
  6. Select "Path" in either "User variables" or "System variables" depending on whether you want this to work for just your user or for all users on your computer.
  7. Add the copied path to the list of paths.
  8. Click "OK".
  9. Open a new command prompt and type "code" to check that VS Code launches, this means you've added the path successfully.
  10. Exit any WSL terminal windows or VS Code instances connected to WSL.
  11. Open a command prompt and type "wsl --shutdown".
  12. Launch a new WSL terminal and see if you can now launch VS Code from the WSL command line using "code".
  13. If it still doesn't work, follow some of other answers for this question involving deleting the ~/.vscode-server and check again if "code" is working.
Karylkarylin answered 1/7, 2023 at 22:35 Comment(0)
K
0

The top answer solved my issue, thanks to @rrmesquita. I cannot upvote or comment yet so I thought I'd add some further information that may be useful to those wanting to troubleshoot if it is happening frequently to them.

What I believe caused this issue for me was when the latest Feb 2024 update of Windows VS Code IDE occurred but somehow the associated update of WSL ~/.vscode-server did not occur when I next launched $ code <my.code-workspace> from my WSL dev directory. What I think triggered the issue was during performing a restart on my PC after a driver update the shutdown process impacted an in-progress background VS Code update. When everything came back up the end-to-end integration between WSL and VS Code was broken. Probably shouldn't have my work running when messing with windows updates ;-p

Symptoms:

  1. In wsl, code did NOT launch the IDE in Windows
  2. In windows, opening IDE showed the WSL extension starting correctly however a dialog eventually appears stating: "...no file system provider found for resource vscode-remote://wsl%2Bubuntu/home/<user>/<dev-directory>/<previously-opened-file.ext>
  3. wsl was working fine, code was working fine, Linux > Ubuntu showing up in Explorer, which code resolving correctly via /mnt/c/Users/<user>/AppData/...

Solution as per top answer, deleting $ rm -r ~/.vscode-server meant that the next invocation of $ code <my.code-workspace> downloaded the latest vs code server presumably aligned to latest VS Code WSL extension.

Korney answered 1/3 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.