Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found

I have Rust installed using WSL2 Ubuntu I have alredy ran basic commands like hello world in rust so cargo is working. I wanted to download the rust-analyzer in VSCODE but I keep getting that error message from the title: rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found

I tried ensuring all paths are correct, all vesions of extension and vscode and rust are up to date. several uninstall re-installs and rustup updates. Toolchain is using stable version. I have reviewed a lot of the other post about this accross all platforms but it seems I can not find the fix. It would be very helpful to get some guidance. Thank you!st

like image 874
Esmir Fernandez Avatar asked Jun 14 '26 15:06

Esmir Fernandez


2 Answers

The solution is to open folder as if in WSL.

  • To do that you need to install this VS code extension called Remote development
  • Than go to the green symbol in the bottom right corner and then select open WSL folder and open folder with your rust project or just open new WSL window

remote development icon

  • The last step is to go to extensions and then search for rust-analyzer and hit install

More info regarding the development on WSL can be found here

like image 184
Pokrt Avatar answered Jun 17 '26 10:06

Pokrt


Remove the rustc and cargo provide by system package manager (e.g. apt).

Install them from offical rustup script instead.

[note]

I just encounter the same problem when using flatpak version of Lapce.

rust-analyzer failed to load workspace: "cargo" "--version" failed: No such file or directory (os error 2)

like image 41
cpprust Avatar answered Jun 17 '26 09:06

cpprust



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!