WSL vscode command returning error "not found"

Viewed 8950

I have this message whenenver i try to type code . enter image description here

Can someone help me please ?

Thanks in advance

6 Answers

Fixed it

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

I have same issue when I trying export my old wsl and move whole project to nvme ssd using new distro.

I able to run the code . on root , but when i switch to my name then it doesn't work, I guess is WSL PATH problem.

I not really familiar to the linux, the below image may easier for you to understand what i am saying.

enter image description here

When i use echo $PATH on wsl to compare root and my account, and i notice that VS code directory only found on root instead of my account.

So i use export PATH=$PATH:"/mnt/c/Users/ricso/AppData/Local/Programs/Microsoft VS Code/bin" to add the VS Code path to my account* and code . is working once i export this.

But the code . will not be able to run again if you restart the wsl, so we need to put in to bashrc.

But when i try to update my account's* PATH using echo "PATH=$PATH:/mnt/c/Users/ricso/AppData/Local/Programs/Microsoft\ VS\ Code/bin" >> ~/.bashrc and restart the wsl to login my account, i notice an error msg popup when run the code .

cannot create /tmp/remote-wsl-loc.txt: Permission denied

And i found this. https://github.com/microsoft/vscode-remote-release/issues/5389

Seem they only giving the workaround for now and hopefully can fix it soon.

*disclaimer above: this code need to run under your account instead of root

**For editing bashrc, instead of using echo and >> write to the file, you also can use code ~/.bashrc to update/edit, when you have the vscode access on wsl.

I just now had the same issue on WSL2 Kali. I tried everything given here: https://github.com/microsoft/vscode-remote-release/issues/2962.

My problem was VS Code was not on Kali's path. Here's how I fixed it :)

echo $PATH
# Confirm PATH is missing this: 
/mnt/c/Users/wcd/AppData/Local/Programs/Microsoft VS Code/bin/

# Confirm VS Code's location then export:
export PATH=$PATH:"/mnt/c/Users/wcd/AppData/Local/Programs/Microsoft VS Code/bin/" 
# It's temporarily added to path...
echo $PATH
# This should now trigger VS Code Server install,
# then open ~/ in VS Code. 
code .

# If above works, make it permanent:
echo 'export PATH=$PATH:"/mnt/c/Users/wcd/AppData/Local/Programs/Microsoft VS Code/bin/"' >> ~/.bashrc

# Restart shell + test
exec "$SHELL"
code .

I solved this problem by opening windows powershell in admin mode and typing the following command:

wsl --update

Then I typed this command to force restart the WSL and all done

wsl --shutdown

For me adding the binary to Path was enough:

export PATH=$PATH:"/mnt/c/Users/%USERNAME%/AppData/Local/Programs/Microsoft VS Code/bin" 

This also happens if you disable the Windows PATH on WSL. I had my VS Code working fine, then when I disable the windows PATH (by editing/creating the /etc/wsl.conf file and inserting the [interop] appendWindowsPath = false parameter) the code command stopped working.

The ek1n8 solution solves my problem, addind the export manually to the WSL Path:

export PATH=$PATH:"/mnt/c/Users/%USERNAME%/AppData/Local/Programs/Microsoft VS Code/bin" 
Related