Visual Studio Code not running/working on WSL 2

18.5k views Asked by At

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.

4

There are 4 answers

6
rrmesquita On

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.

1
oleksii.sapov-erlinger On

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

0
CT0 On

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.
0
jfhOz On

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.