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.
Visual Studio Code not running/working on WSL 2
18.5k views Asked by rrmesquita AtThere are 4 answers
I solved it following this post with slight modifications.
- exit all instaces of wsl
- From the power shell run
wsl --shutdown
- Start VS Code on Windows
- Open a previously saved project which uses wsl (this is the difference)
- Open wsl and run
code .
starts VS Code for me
Note: the issue appeared for me after upgrading to wsl2
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.
- 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.
- If the file displayed in Windows Explorer is also a shortcut, then again right click and select "Open File Location".
- Repeat if necessary until you find yourself in a folder probably named "Microsoft VS Code" with a sub-folder named "bin".
- 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.
- In your start menu find "view advanced system settings" and launch it. Click "Environment Variables"
- 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.
- Add the copied path to the list of paths.
- Click "OK".
- Open a new command prompt and type "code" to check that VS Code launches, this means you've added the path successfully.
- Exit any WSL terminal windows or VS Code instances connected to WSL.
- Open a command prompt and type "wsl --shutdown".
- Launch a new WSL terminal and see if you can now launch VS Code from the WSL command line using "code".
- 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.
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:
- In wsl,
code
did NOT launch the IDE in Windows - 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>
- 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.
After some research, what really fixed the issue for me was this:
rm -r ~/.vscode-server
to delete the VS Code WSL server.wsl --shutdown
.Then you can go back to WSL and run
code .
and it should work normally.