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

Viewed 8089

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?

9 Answers

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.

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

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.

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)

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

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

In WSL run: code .

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.

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.

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

Related