Jérome BORGA
Jérome BORGA

Reputation: 695

WSL vscode command returning error "not found"

I have this message whenever I try to type code .

Screen capture containing an output obtained probably at a Unix-based WSL 2 terminal running on Windows. The output text is quoted exactly in the rest of the question for accessibility.

/mnt/c/Users/jerom/.vscode/extensions/ms-vscode-remote.remote-wsl-0.63.13/scripts/wslCode.sh: 69: /home/jerome/.vscode-server-server/bin/f80445acd5a3dadef24aa209168452a3d97cc326/bin/code: not found

Can someone help me please?

Thanks in advance

Upvotes: 22

Views: 82208

Answers (21)

dheuvels
dheuvels

Reputation: 156

I had the problem after updating to VSCode 1.90.0. The message was rather specific about this file:

/home/<my-user>/.vscode-server/bin/<id>/node: not found

And that file was actually missing (pretty sure, I didn't remove it myself):

$ ls /home/<my-user>/.vscode-server/bin/<id>/node
ls: cannot access (..)

After doing some of the proposed fixes above (like wsl --update), I removed the .vscode-server folder:

$ mv ~/.vscode-server ~/_.vscode-server.old

On the next "Connect to WSL" from VSCode on the Windows side, it said "Installing server.." and brought back the required files.

Upvotes: 2

MiniSu
MiniSu

Reputation: 590

I just reinstalled VS code and then went to WSL ubuntu shell and typed code . . It started working

Upvotes: 0

user2866001
user2866001

Reputation: 69

Case sensitivity matters as well. I had to use Code.exe . after adding the folder to $PATH.

Upvotes: 0

Ashikul Islam Sawan
Ashikul Islam Sawan

Reputation: 1020

Simply: It's the same command code . from your desired directory.

Note: You must need to install wsl extension in your VS Code

Upvotes: 0

Istv&#225;n Magyary
Istv&#225;n Magyary

Reputation: 1

I was using the Mamba package manager, and VSCode was in the path, but it didn't work. After I uninstalled mamba, it worked. I'm not sure why.

Upvotes: 0

NeutronBR
NeutronBR

Reputation: 1

Tried a bunch of stuff. I believe I lost myself trying to fix some packages. I tried

rm -rf ~/.vscode-server/
wsl --shutdown

Reinstalling my WSL plugin on VSCode. What really made it to get back working for me was

wsl --update

In my case, the WSL connection was effective, but no code command inside bash. The error was

run-detectors: unable to find an interpreter for /mnt/c/Users/myuser/AppData/Local/Programs/Microsoft VS Code/Code.exe

Upvotes: 0

zenoir
zenoir

Reputation: 21

What worked for me was:

  1. Enter Wsl and do:
rm -rf ~/.vscode-server/data
  1. Then, open Task Manager and end all VS Code related tasks.
  2. Open VS Code :)

Upvotes: 2

Graps
Graps

Reputation: 49

For who are using Insiders version (and have uninstalled stable version), you should use command code-insiders . instead code .

If you wish to use just code ., go to the win folder: \Users\:userprofile\AppData\Local\Programs\Microsoft VS Code Insiders\bin

and clone the file code-insiders, renaiming to code

Upvotes: 0

you just need to add .bashrc file with: export PATH=$PATH:"/mnt/c/Users//AppData/Local/Programs/Microsoft VS Code/bin"

Upvotes: 0

Ling
Ling

Reputation: 9

what worked for me was :

wsl --shutdown

and then

wsl --restart

Upvotes: -1

Bevan
Bevan

Reputation: 44307

I found another solution.

On my machine, Visual Studio Code had been installed by an Admin for all users, and I found that not only was code . not available within my WSL environment, but commands like Dev Container: Reopen in Container failed to work as well.

Installing a private copy of Visual Studio Code (which is the normal default), made everything work.

$ which code
/mnt/c/Users/bearps/AppData/Local/Programs/Microsoft VS Code/bin/code

To check your situation, open a PowerShell prompt and run

PS> get-command code
CommandType     Name        Version    Source
-----------     ----        -------    ------
Application     code.cmd    0.0.0.0    C:\Users\bearps\AppData\Local\Programs\Microso...

If the location shown is under C:\Program Files or C:\Program Files (x86) try switching to a local install.

Upvotes: 0

user15295109
user15295109

Reputation:

Go to VS code on Windows, extensions -> WSL, install it. Then restart the WSL subsystem and will work.

Upvotes: 0

dexter0323
dexter0323

Reputation: 613

Try these 5 simple steps:

  1. Stop WSL: On the PowerShell type wsl --shutdown
  2. Uninstall VS Code WSL extension
  3. Install VS Code WSL extension again
  4. Start WSL with the user you like to try code command, typing on PowerShell the following command wsl ~ -u MyUser
  5. Navigate to your app directory and type code . on the batch terminal or specify the whole path code ./myapps/hello-world-app

Upvotes: 2

Amani Kilumanga
Amani Kilumanga

Reputation: 324

I just ran into this issue after setting up WSL and vscode on a new computer.

The solution that worked for me was to sign out of windows. Once I logged back in the PATH env variable seemed correct and launching vscode from WSL worked as expected.

Upvotes: 0

Elia Weiss
Elia Weiss

Reputation: 9866

For me it was wsl using the wrong container:

 wsl --list -v
  NAME                   STATE           VERSION
* docker-desktop-data    Stopped         2
  Ubuntu                 Running         2

I did wsl -s ubuntu

 wsl --list -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop-data    Stopped         2

and it solved the problem

Upvotes: 1

Felipe Cararo
Felipe Cararo

Reputation: 129

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

Upvotes: 13

wcDogg
wcDogg

Reputation: 647

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 .

Upvotes: 39

J&#233;rome BORGA
J&#233;rome BORGA

Reputation: 695

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.

Upvotes: 25

Andy
Andy

Reputation: 121

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" 

Upvotes: 12

tertek
tertek

Reputation: 1002

For me adding the binary to Path was enough:

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

Upvotes: 4

Ricson Goo
Ricson Goo

Reputation: 101

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.

Upvotes: 5

Related Questions