4

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.

rrmesquita
  • 466
  • 1
  • 5
  • 15

3 Answers3

20

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.

rrmesquita
  • 466
  • 1
  • 5
  • 15
2

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

o-sapov
  • 320
  • 2
  • 13
  • For me, `wsl --shutdown` causes Windows 10 to halt, but terminating the distros manually and closing wsl hosts from task manager works. – theSparky Aug 25 '23 at 20:46
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.
CT0
  • 11
  • 1