'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?
Solution 1:[1]
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:
- Open VS Code on Windows
- Open Extensions and then search on WSL
- It should say the extension needs to be reloaded - go ahead and reload it
- Open WSL and type code
- This should force another upgrade of code and this time it should launch.
Solution 2:[2]
Just run Vscode normally on windows. This will load wsl extension and solve the issue.
Solution 3:[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.
Solution 4:[4]
A simple sudo apt update -y and then rerunning code . fixed this for me.
Solution 5:[5]
Keep it simple S*upid method:
- Download & install vscode again. link for windows
- (Ubuntu example)
apt update && yes | apt upgrade - 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)
Solution 6:[6]
In C:\Users<user>.vscode rename path ms-vscode-remote.remote-wsl- to ms-remote-wsl-old
In WSL run: code .
Solution 7:[7]
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.
Solution 8:[8]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
