Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Remote - Can't run 'code' command in WSL Ubuntu 18 or WSL 2 Ubuntu 20 - wrong path

I'm having an issue when I try to run the code command from Visual Studio Code in WSL Ubuntu. I get the following error:

$ code .

/mnt/c/Users/Name/.vscode/extensions/ms-vscode-remote.remote-wsl-0.64.2/scripts/wslCode.sh: 63: /mnt/c/Users/Name/.vscode/extensions/ms-vscode-remote.remote-wsl-0.64.2/scripts/wslCode.sh: /home/barry/.vscode/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/bin/remote-cli/code: not found

When I run the following, it installs the VS Code Server and the command works as expected:

$ /mnt/c/Users/Name/AppData/Local/Programs/Microsoft\ VS\ Code/bin/code .

When I run which -a code, I can see I have two paths related to this command and I believe the correct one is /mnt/c/Users/Name/AppData/Local/Programs/Microsoft VS Code/bin/code, but I don't know how to remove the first one or how it even related two paths to this command in the first place?

barry@RandomName:~$ which -a code
/mnt/c/Program Files/Microsoft VS Code/bin/code
/mnt/c/Users/Name/AppData/Local/Programs/Microsoft VS Code/bin/code

Can anyone help please?

like image 714
Sprouter Avatar asked Nov 17 '25 14:11

Sprouter


2 Answers

I've had this issue and it was solved doing:

  1. Open Terminal on Windows and Type wsl
  2. You will be on the wsl env
  3. Type rm -rf ~/.vscode-server
  4. Type logout to leave the wsl env
  5. Then type wsl --shutdown
  6. Try to Open VSCode and connect with WSL.
like image 180
João Paulo Dias Avatar answered Nov 20 '25 05:11

João Paulo Dias


Ran into the same problem 5 min ago and this post from thesteve0 worked for me:

https://github.com/microsoft/vscode-remote-release/issues/6294#issuecomment-1031974516

Quoting from the original post:

  1. Open VS Code on Windows
  2. Open Extensions and then search on WSL
  3. It should say the extension needs to be reloaded - go ahead and reload it
  4. Open WSL and type code
  5. This should force another upgrade of code and this time it should launch.
like image 39
pckben Avatar answered Nov 20 '25 05:11

pckben