10

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?

Sprouter
  • 312
  • 1
  • 2
  • 10

13 Answers13

17

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.
pckben
  • 867
  • 2
  • 9
  • 24
3

I've managed to 'solve' it by creating a new Symlink to the correct directory so this one gets run first. I couldn't find a way to remove the incorrect directory so would appreciate it if someone knows a cleaner solution?

To add the Symlink, I ran ln -s /mnt/c/Users/Name/AppData/Local/Programs/Microsoft\ VS\ Code/bin/code /usr/local/bin/code

So now I have these 3 paths for the code command:

$ which -a code

/usr/local/bin/code
/mnt/c/Program Files/Microsoft VS Code/bin/code
/mnt/c/Users/Name/AppData/Local/Programs/Microsoft VS Code/bin/code

Whenever I tried to remove rm or unlink /mnt/c/Program Files/Microsoft VS Code/bin/code (with sudo), I get permission denied.

Sprouter
  • 312
  • 1
  • 2
  • 10
3

A simple sudo apt update -y and then rerunning code . fixed this for me.

3

Just run Vscode normally on windows. This will load wsl extension and solve the issue.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 12:31
3

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.
2

I ran into same error but any answer works for me until I saw this issue at github.

Make sure you don't use any software that depends on systemd, like snap, microk8s, etc.

https://github.com/microsoft/WSL/issues/8952

Quoting from the original post:

"Disabling systemd support in /etc/wsl.conf resolves the issue."

/etc/wsl.conf (make sure you don't use any software that depends on systemd, like snap, microk8s, etc)

[boot]
#systemd = true

Just need to comment "systemd" and relaunch wsl

MagicTaco
  • 121
  • 2
  • 5
  • This caused my WSL instance to stop booting with a "The semaphore timeout period has expired" error. (With error code Wsl/0x80070079). – Duff Aug 03 '23 at 14:11
  • do you use any software that depends on systemd? – MagicTaco Aug 03 '23 at 16:21
  • Not that I'm aware of, although I'm not certain how to tell, either. I was able to finally get in. I'm not sure whether it was due to me just waiting and relaunching the terminal after the wait or by accessing the `\\wsl$` share through Windows. – Duff Aug 04 '23 at 15:33
1

Keep it simple S*upid method:

  1. Download & install vscode again. link for windows
  1. (Ubuntu example) apt update && yes | apt upgrade
  2. Try to launch code from wsl

You should see something like:

Updating VS Code Server to version 5554b12acf27056905806867f251c859323ff7e9
Removing previous installation...
Installing VS Code Server for x64 (5554b12acf27056905806867f251c859323ff7e9)
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Idan Banani
  • 131
  • 2
  • 13
1

In my case the extension in VS Code was not in a state needing reload like in the most upvoted answer. What helped after multiple attempts:

  1. Terminate the WSL2 distribution (from the Windows CLI): wsl -t Ubuntu (replace Ubuntu with your distribution name)
  2. Check that it is stopped: wsl -l -v
  3. Start your WSL distribution again.

In my case the command code started to be accessible through a Windows directory: /mnt/c/Users/username/AppData/Local/Programs/Microsoft VS Code/bin/code

1

I fixed my issue by opening wsl and removing the .vscode-server

rm -rf .vscode-server

i followed this link link to fix

Adam Muse
  • 151
  • 1
  • 6
0

In C:\Users<user>.vscode rename path ms-vscode-remote.remote-wsl- to ms-remote-wsl-old

In WSL run: code .

0

I got two versions of Visual Studio Code installed, one said "(user)". I uninstalled both and installed the newest version via winget.

That fixed it for me.

nyndo
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '22 at 19:28
0

I have got two different versions of visual studio code installed on my PC. I have uninstalled the older version keeping the latest one. This resolved issue for me.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '22 at 03:13
0

I try to avoid using the Windows PATH in WSL. I added manual aliases to my ~/.bashrc, e.g. for code .:

alias code='"/c/Program Files/Microsoft VS Code/bin/code" .'
Alex
  • 2,784
  • 2
  • 32
  • 46