rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

The terminal process failed to launch: Path to shell executable "cargo" does not exist.

Open RodogInfinite opened this issue 4 years ago • 9 comments

When clicking Run I get this in the terminal:

> Executing task: cargo run --package helloworld --bin helloworld <

The terminal process failed to launch: Path to shell executable "cargo" does not exist.

Terminal will be reused by tasks, press any key to close it.

rust-analyzer version: rust-analyzer version: 5fae65dd2 2022-03-07 stable

rustc version: rustc 1.61.0-nightly (458262b13 2022-03-09)

relevant settings:

"rust-analyzer.server.extraEnv": {
      "CARGO": "/opt/rust/cargo/bin/cargo",
      "RUSTC": "/opt/rust/cargo/bin/rustc",
    },

Additional Information:

When I use:

"rust-analyzer.server.extraEnv": {
      // "CARGO": "/opt/rust/cargo/bin/cargo",
      "RUSTC": "/opt/rust/cargo/bin/rustc",
    },

I get

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

and when I use:

"rust-analyzer.server.extraEnv": {
      "CARGO": "/opt/rust/cargo/bin/cargo",
      //"RUSTC": "/opt/rust/cargo/bin/rustc",
    },
rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /mnt/helloworld/Cargo.toml. Is rust-src installed?: "rustc" "--print" "sysroot" failed: No such file or directory (os error 2)

I'm using Code-Server to install the .vsix directly using code-server --install-extension rust-analyzer-linux-x64.vsix. The behavior should be the same as a locally installed copy of VSCode since Code-Server uses a fork of it under the hood.

When I run directly from the terminal:

> cargo run
   Compiling helloworld v0.1.0 (/mnt/helloworld)
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/helloworld`
Hello, world!

Installed components :

> rustup component list --installed
cargo-x86_64-unknown-linux-gnu
clippy-x86_64-unknown-linux-gnu
rust-analysis-x86_64-unknown-linux-gnu
rust-docs-x86_64-unknown-linux-gnu
rust-src
rust-std-x86_64-unknown-linux-gnu
rustc-x86_64-unknown-linux-gnu
rustfmt-x86_64-unknown-linux-gnu

I've also tried these settings with no change to behavior:

{
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.automationProfile.linux": {"path":"/bin/bash"},
}

RodogInfinite avatar Mar 10 '22 19:03 RodogInfinite

/opt/rust/cargo/bin is not in your PATH when connecting via VS Code. I think there should be some ways to set environment variables for remote connections.

lnicola avatar Mar 10 '22 19:03 lnicola

I guess the one setting I didn't mention is that I have is:

{"terminal.integrated.env.linux": {
      "PATH": "/usr/lib/code-server/vendor/modules/code-oss-dev/bin:/opt/versions/node/v16.14.0/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    },

which puts it on the path and is why I can run cargo in the terminal.

So altogether for the relevant settings I have:

{
    "terminal.integrated.env.linux": {
      "PATH": "/usr/lib/code-server/vendor/modules/code-oss-dev/bin:/opt/versions/node/v16.14.0/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    },
    "rust-analyzer.server.extraEnv": {
      "CARGO": "/opt/rust/cargo/bin/cargo",
      "RUSTC": "/opt/rust/cargo/bin/rustc",
    },
}

RodogInfinite avatar Mar 10 '22 19:03 RodogInfinite

That only applies to the integrated terminal, not to the code-server process. You might need to add it to ~/.bash_profile or something.

lnicola avatar Mar 10 '22 19:03 lnicola

I added "rust-analyzer.runnableEnv": {"PATH": "/opt/rust/cargo/bin"} and it works now

now the settings.json looks like this:

{
    "terminal.integrated.env.linux": {
      "PATH": "/usr/lib/code-server/vendor/modules/code-oss-dev/bin:/opt/versions/node/v16.14.0/bin:/opt/rust/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    },
    "rust-analyzer.server.extraEnv": {
      "CARGO": "/opt/rust/cargo/bin/cargo",
      "RUSTC": "/opt/rust/cargo/bin/rustc",
    },
    "rust-analyzer.runnableEnv": {"PATH": "/opt/rust/cargo/bin"}
}

RodogInfinite avatar Mar 10 '22 20:03 RodogInfinite

for those who 1) use vscode remotely, 2) can run cargo in terminal, but vscode can't found cargo:

Final Solution

Kill the running vscode server, then reload the vscode.

Steps

  1. go to panel "Output" -> "Remote - SSH"
  2. get the server pid from output like this:
 [12:36:33.333] [server] Found running server (pid=782060)
  1. kill the process by pid
  2. reload the vscode

XiaochenCui avatar Aug 19 '24 19:08 XiaochenCui

for those who 1) use vscode remotely, 2) can run cargo in terminal, but vscode can't found cargo:

Final Solution

Kill the running vscode server, then reload the vscode.

Steps

  1. go to panel "Output" -> "Remote - SSH"
  2. get the server pid from output like this:
 [12:36:33.333] [server] Found running server (pid=782060)
  1. kill the process by pid
  2. reload the vscode

Thank you, this realy help me.

han-ian avatar Aug 20 '24 07:08 han-ian

{ "rust-analyzer.restartServerOnConfigChange": true, "rust-analyzer.runnables.extraEnv": {"PATH": "${env:HOME}/.cargo/bin:${env:PATH}"} }

jocagovi avatar Jan 23 '25 08:01 jocagovi

reload

Work for me, thank you so much!!!

ramamimu avatar Nov 08 '25 03:11 ramamimu

{ "rust-analyzer.restartServerOnConfigChange": true, "rust-analyzer.runnables.extraEnv": {"PATH": "${env:HOME}/.cargo/bin:${env:PATH}"} }

This is what worked for me! Thank you so much, I tried all the other solutions and they didn't fix it fully T-T

theminji avatar May 17 '26 18:05 theminji