Skip to content
Latchkey

Rust "rustup: command not found" in CI

The shell could not find rustup (or cargo) on PATH. Either Rust was never installed on the runner, or it is installed but ~/.cargo/bin was never added to PATH for this step.

What this error means

A step calling rustup or cargo fails instantly with "command not found", even on an image that supposedly has Rust. Common on bare images or after installing rustup in a previous step without exporting PATH.

Terminal
./ci/build.sh: line 3: rustup: command not found
# or
cargo: command not found

Diagnose it: toolchain, features, cache

Terminal
rustc --version --verbose && cargo --version
cat rust-toolchain.toml 2>/dev/null
cargo tree -e features | head -30
cargo clean && cargo build --locked

Common causes

Rust not installed on the runner

A minimal base image ships no Rust toolchain. rustup and cargo simply do not exist until you install them.

~/.cargo/bin not on PATH

rustup installs binaries to ~/.cargo/bin. If that directory isn’t on PATH - or a later step starts a fresh shell that never sourced ~/.cargo/env - the commands aren’t found.

How to fix it

Install rustup and add it to PATH

Terminal
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
rustc --version

Persist cargo bin to the job PATH

In GitHub Actions, write ~/.cargo/bin to $GITHUB_PATH so every later step finds cargo.

.github/workflows/ci.yml
- run: |
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- run: cargo build   # now resolves

How to prevent it

  • Use a setup action (e.g. dtolnay/rust-toolchain) instead of installing by hand.
  • Add ~/.cargo/bin to $GITHUB_PATH so all steps see cargo.
  • Use the official rust Docker image when you control the container.

Frequently asked questions

What causes Rust "rustup: command not found" in CI?
There are 2 common causes: rust not installed on the runner and ~/.cargo/bin not on path. A minimal base image ships no Rust toolchain.
How do I fix Rust "rustup: command not found" in CI?
There are 2 fixes depending on which cause you have: install rustup and add it to path and persist cargo bin to the job path. Work through them in order, since the first is the most common.
What does Rust "rustup: command not found" in CI actually mean?
A step calling rustup or cargo fails instantly with "command not found", even on an image that supposedly has Rust.
How do I stop Rust "rustup: command not found" in CI happening again?
Use a setup action (e.g. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card